Home | Trees | Indices | Help |
|
---|
|
1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # 4 # Copyright © 2010 Red Hat, Inc. 5 # 6 # This software is licensed to you under the GNU General Public License, 7 # version 2 (GPLv2). There is NO WARRANTY for this software, express or 8 # implied, including the implied warranties of MERCHANTABILITY or FITNESS 9 # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 10 # along with this software; if not, see 11 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 12 # 13 # Red Hat trademarks are not licensed under GPLv2. No permission is 14 # granted to use or replicate Red Hat trademarks that are incorporated 15 # in this software or its documentation. 16 17 """ 18 Taken from stackoverflow.com : http://tinyurl.com/2f6gx7s 19 """ 20 21 from hashlib import sha256 22 from hmac import HMAC 23 import random 24 25 26 NUM_ITERATIONS = 5000 27 2830 return "".join(chr(random.randrange(256)) for i in xrange(num_bytes))3133 result = password 34 for i in xrange(iterations): 35 result = HMAC(result, salt, sha256).digest() # use HMAC to apply the salt 36 return result37 3840 salt = random_bytes(8) # 64 bits 41 hashed_password = pbkdf_sha256(plain_password, salt, NUM_ITERATIONS) 42 # return the salt and hashed password, encoded in base64 and split with "," 43 return salt.encode("base64").strip() + "," + hashed_password.encode("base64").strip()4446 salt, hashed_password = saved_password_entry.split(",") 47 salt = salt.decode("base64") 48 hashed_password = hashed_password.decode("base64") 49 pbkdbf = pbkdf_sha256(plain_password, salt, NUM_ITERATIONS) 50 return hashed_password == pbkdbf51
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Sep 7 12:30:37 2010 | http://epydoc.sourceforge.net |