在Windows中获取登录用户的用户名/密码

在Windows中获取登录用户的用户名/密码

问题描述:

在Windows中是否有任何API可以获取当前登录的用户名和密码?

Is there any API to get the currently logged in user's name and password in Windows?

谢谢.

密码:不,出于安全原因不保留此密码-已使用,然后丢弃.您可以从注册表中获取此用户的加密密码(具有足够的特权),然后使用彩虹表进行解密,但是使用当前方法非常耗费资源并且非常耗时.更好地提示用户.

Password: No, this is not retained for security reasons - it's used, then discarded. You could retrieve the encrypted password for this user from the registry, given sufficient privileges, then decrypt it using something like rainbow tables, but that's extremely resource intensive and time consuming using current methods. Much better to prompt the user.

或者,如果您要像Novell一样实现某种单点登录"系统,则应通过GINA(Vista之前的版本)或凭据提供程序(Vista)来实现,这将导致您的代码被在登录时输入用户名和密码,这是唯一可以使用密码的时间.

Alternatively, if you want to implement some sort of 'single signon' system as Novell does, you should do it via either a GINA (pre-Vista) or a Credential Provider (Vista), which will result in your code being given the username and password at login, the only time at which the password is available.

对于用户名,获取当前用户名(运行代码的人)很容易:AdvApi32.dll中的GetUserName函数正是为您完成的.

For username, getting the current username (the one who is running your code) is easy: the GetUserName function in AdvApi32.dll does exactly this for you.

如果您正在作为服务运行,则需要记住没有一个登录用户":除了任何实际人员之外,随时都有多个用户,例如LocalSystem,NetworkService,SYSTEM和其他帐户. 本文提供了一些示例代码和文档.

If you're running as a service, you need to remember there is no one "logged in user": there are several at any time, such as LocalSystem, NetworkService, SYSTEM and other accounts, in addition to any actual people. This article provides some sample code and documentation for doing that.