开发者

Python: Get Windows username of user viewing page?

开发者 https://www.devze.com 2023-02-14 03:38 出处:网络
Is there a way in Python/Django to get the username of the currently logged-in Windows user, from an app that is not running locally?

Is there a way in Python/Django to get the username of the currently logged-in Windows user, from an app that is not running locally?

UPDATE: sorry, to clarify, by this I mean the Windows username of the user viewing the web page, not the user running the server.

I've tried both:

 current_user = os.environ.get("USERNAME")
 current_user_getpass = getpass.getuser()

But I think they're returning the name of the user running the server.

Thanks!

FURTHER UPDATE: I don't care greatly about security. It really doesn't matter if users spoof a username. What does matter is convenience. I just need a way to get the username without users having to 开发者_如何学Pythonfiddle around with passwords or install client-side software. Any ideas?


Three ways, none of which work.

  1. Use the Ident (AUTH) protocol. It's technically cross-platform.

    ...except there are exactly zero Ident servers for Windows that are able to return the real user name instead of a static string.

    Edit: Apparently Retina Scan Identd can do this. (Awesome.)

  2. Require HTTP NTLM or Negotiate authentication. You get more than a mere username check,

    ...except NTLM is insecure, only Internet Exploder and Firefox support it, and they only use it inside the LAN (intranet) by default. Negotiate is able to use the more secure Kerberos, but it (obviously) requires Kerberos on both server and clients. If the Windows PCs are in a domain, good. If not...

  3. If you control all client machines, you can use simple SSL client-certificate authentication. Works in all modern browsers.

    ...but every user needs their own certificate. Creating an internal-use CA and issuing certificates is simple; getting them installed and working in client machines - not so.

0

精彩评论

暂无评论...
验证码 换一张
取 消