File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,18 +131,20 @@ Examples
131131
132132A simple example illustrating typical use::
133133
134- import crypt, getpass, pwd
134+ import pwd
135+ import crypt
136+ import getpass
135137
136138 def login():
137- username = input('Python login:')
139+ username = input('Python login: ')
138140 cryptedpasswd = pwd.getpwnam(username)[1]
139141 if cryptedpasswd:
140142 if cryptedpasswd == 'x' or cryptedpasswd == '*':
141- raise "Sorry, currently no support for shadow passwords"
143+ raise ValueError(' no support for shadow passwords')
142144 cleartext = getpass.getpass()
143145 return crypt.crypt(cleartext, cryptedpasswd) == cryptedpasswd
144146 else:
145- return 1
147+ return True
146148
147149To generate a hash of a password using the strongest available method and
148150check it against the original::
@@ -151,4 +153,4 @@ check it against the original::
151153
152154 hashed = crypt.crypt(plaintext)
153155 if hashed != crypt.crypt(plaintext, hashed):
154- raise "Hashed version doesn't validate against original"
156+ raise ValueError("hashed version doesn't validate against original")
You can’t perform that action at this time.
0 commit comments