Skip to main content
Windows/Unix.
Source Link
Mateen Ulhaq
  • 27.9k
  • 21
  • 121
  • 155

You can probably useWindows:

os.environ.get('USERNAME') 

orLinux:

os.environ.get('USER') 

But it's not going to be safe because environment variablesBoth:

os.environ.get('USER', os.environ.get('USERNAME')) 

Note that environment variables can be modified by the user, so this is a potential security vulnerability. With this method, an attacker can be changedeasily fake their username.

You can probably use:

os.environ.get('USERNAME') 

or

os.environ.get('USER') 

But it's not going to be safe because environment variables can be changed.

Windows:

os.environ.get('USERNAME') 

Linux:

os.environ.get('USER') 

Both:

os.environ.get('USER', os.environ.get('USERNAME')) 

Note that environment variables can be modified by the user, so this is a potential security vulnerability. With this method, an attacker can easily fake their username.

USER or USERNAME
Source Link
Aaron McDaid
  • 27.3k
  • 10
  • 73
  • 95

You can probably use:

os.environ.get('USERNAME') 

or

os.environ.get('USER') 

But it's not going to be safe because environment variables can be changed.

You can probably use:

os.environ.get('USERNAME') 

But it's not going to be safe because environment variables can be changed.

You can probably use:

os.environ.get('USERNAME') 

or

os.environ.get('USER') 

But it's not going to be safe because environment variables can be changed.

added 5 characters in body
Source Link
Saullo G. P. Castro
  • 59.4k
  • 28
  • 191
  • 244

You can probably use:

os.getenvenviron.get('USERNAME') 

But it's not going to be safe because environment variables can be changed.

You can probably use:

os.getenv('USERNAME') 

But it's not going to be safe because environment variables can be changed.

You can probably use:

os.environ.get('USERNAME') 

But it's not going to be safe because environment variables can be changed.

Source Link
Nadia Alramli
  • 115.5k
  • 39
  • 176
  • 152
Loading