Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Get Windows username of user viewing page?

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 fiddle around with passwords or install client-side software. Any ideas?

like image 884
AP257 Avatar asked Nov 05 '22 01:11

AP257


1 Answers

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.

like image 87
user1686 Avatar answered Nov 12 '22 16:11

user1686