Skip to content

Instantly share code, notes, and snippets.

@vijayanandrp
Created June 14, 2017 20:38
Show Gist options
  • Save vijayanandrp/7ba1ec1c03c0c8d2240a0af882d41fcc to your computer and use it in GitHub Desktop.
Save vijayanandrp/7ba1ec1c03c0c8d2240a0af882d41fcc to your computer and use it in GitHub Desktop.
crypt, pwd, getpass - Understand by quick example
#!/usr/bin/python
import crypt, getpass, pwd
def main():
print "##### This programs helps to understand the username/password storage in Operating System #######\n"
username = raw_input('Python login:')
try:
cryptedpasswd = pwd.getpwnam(username).pw_passwd
except KeyError:
print "Sorry user name not found"
return 0
except exception as er:
print "Exception: "+str(er)
return 0
if cryptedpasswd:
if 'x' in cryptedpasswd or '*' in cryptedpasswd:
raise NotImplementedError("Sorry, currently no support for shadow passwords")
cleartext = getpass.getpass()
print "salted value: "+str(crypt.crypt(cleartext, cryptedpasswd))
return crypt.crypt(cleartext, cryptedpasswd) == cryptedpasswd
else:
return 1
if __name__ == "__main__":
try:
main()
except NotImplementedError:
print "Sorry, currently no support for shadow passwords"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment