diff options
author | Éric Araujo <merwok@netwok.org> | 2011-05-29 01:24:45 (GMT) |
---|---|---|
committer | Éric Araujo <merwok@netwok.org> | 2011-05-29 01:24:45 (GMT) |
commit | bc57789dafaadd3652b7f02a2b17684b6c74055e (patch) | |
tree | 753468f871d35e5bb369028eff3669a2149317e8 /Doc | |
parent | 7f9b37be4510e701184896dd22994412455e6e8b (diff) | |
download | cpython-bc57789dafaadd3652b7f02a2b17684b6c74055e.zip cpython-bc57789dafaadd3652b7f02a2b17684b6c74055e.tar.gz cpython-bc57789dafaadd3652b7f02a2b17684b6c74055e.tar.bz2 |
Improve example for crypt module. No string exceptions..
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/crypt.rst | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Doc/library/crypt.rst b/Doc/library/crypt.rst index ec5a4b0..27236c1 100644 --- a/Doc/library/crypt.rst +++ b/Doc/library/crypt.rst @@ -131,18 +131,20 @@ Examples A simple example illustrating typical use:: - import crypt, getpass, pwd + import pwd + import crypt + import getpass def login(): - username = input('Python login:') + username = input('Python login: ') cryptedpasswd = pwd.getpwnam(username)[1] if cryptedpasswd: if cryptedpasswd == 'x' or cryptedpasswd == '*': - raise "Sorry, currently no support for shadow passwords" + raise ValueError('no support for shadow passwords') cleartext = getpass.getpass() return crypt.crypt(cleartext, cryptedpasswd) == cryptedpasswd else: - return 1 + return True To generate a hash of a password using the strongest available method and check it against the original:: @@ -151,4 +153,4 @@ check it against the original:: hashed = crypt.crypt(plaintext) if hashed != crypt.crypt(plaintext, hashed): - raise "Hashed version doesn't validate against original" + raise ValueError("hashed version doesn't validate against original") |