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

Getting user name/password of the logged in user in Windows(在 Windows 中获取登录用户的用户名/密码)

本文介绍了在 Windows 中获取登录用户的用户名/密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这篇关于在 Windows 中获取登录用户的用户名/密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 Windows 中获取登录用户的用户名/密码

基础教程推荐