X-Git-Url: https://mudpy.org/gitweb?a=blobdiff_plain;f=lib%2Fmudpy%2Fpassword.py;h=2e37b9130e4b9a57c1d6c3d8843dbf0550f5ade1;hb=b6b6478cf56b8d0defd158868c91f88c150313ed;hp=f6c1abc5562cf4a13b82660346361933e816b139;hpb=e0a20398d5cae3ea927132fb29a1bf76d0bb239a;p=mudpy.git diff --git a/lib/mudpy/password.py b/lib/mudpy/password.py index f6c1abc..2e37b91 100644 --- a/lib/mudpy/password.py +++ b/lib/mudpy/password.py @@ -1,7 +1,6 @@ -# -*- coding: utf-8 -*- """Password hashing functions and constants for the mudpy engine.""" -# Copyright (c) 2004-2014 Jeremy Stanley . Permission +# Copyright (c) 2004-2015 Jeremy Stanley . Permission # to use, copy, modify, and distribute this software is granted under # terms provided in the LICENSE file distributed with this software. @@ -23,7 +22,8 @@ SHA512 = 5 # hashlib.sha512 def _pack_bytes(numbers): - """ + """Make a packed byte sequence: + This is a wrapper around struct.pack, used to turn a list of integers between 0 and 255 into a packed sequence akin to a C-style string. """ @@ -36,7 +36,8 @@ def _pack_bytes(numbers): def _bytes_to_text(byte_sequence): - """ + """Generate printable representation of 8-bit data: + This is a wrapper around base64.b64encode with preferences appropriate for encoding Unix-style passwd hash strings. """ @@ -47,7 +48,8 @@ def _bytes_to_text(byte_sequence): def _generate_salt(salt_len=2): - """ + """Generate salt for a password hash: + This simply generates a sequence of pseudo-random characters (with 6-bits of effective entropy per character). Since it relies on base64 encoding (which operates on 6-bit chunks of data), we only generate @@ -62,7 +64,8 @@ def _generate_salt(salt_len=2): def upgrade_legacy_hash(legacy_hash, salt, sep="$"): - """ + """Upgrade an older password hash: + This utility function is meant to provide a migration path for users of mudpy's legacy account-name-salted MD5 hexdigest password hashes. By passing the old passhash (as legacy_hash) and name (as salt) @@ -95,7 +98,8 @@ def create( salt_len=2, sep="$" ): - """ + """Generate a password hash: + The meat of the module, this function takes a provided password and generates a Unix-like passwd hash suitable for storage in portable, text-based data files. The password is prepended with a salt (which @@ -173,7 +177,8 @@ def create( def verify(password, encoded_hash): - """ + """Verify a password: + This simple function requires a text password and a mudpy-format password hash (as generated by the create function). It returns True if the password, hashed with the parameters from the encoded_hash,