<s> import bcrypt <EOL> from website import settings <EOL> def generate_password_hash ( password , rounds = None ) : <EOL> '''<STR_LIT>''' <EOL> if rounds is None : <EOL> rounds = settings . BCRYPT_LOG_ROUNDS <EOL> if not password : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> pw_hash = bcrypt . hashpw ( <EOL> unicode ( password ) . encode ( '<STR_LIT:utf-8>' ) , <EOL> bcrypt . gensalt ( rounds ) <EOL> ) <EOL> return pw_hash <EOL> def constant_time_compare ( val1 , val2 ) : <EOL> '''<STR_LIT>''' <EOL> if len ( val1 ) != len ( val2 ) : <EOL> return False <EOL> result = <NUM_LIT:0> <EOL> for x , y in zip ( val1 , val2 ) : <EOL> result |= ord ( x ) ^ ord ( y ) <EOL> return result == <NUM_LIT:0> <EOL> def check_password_hash ( pw_hash , password ) : <EOL> '''<STR_LIT>''' <EOL> return constant_time_compare ( <EOL> bcrypt . hashpw ( <EOL> unicode ( password ) . encode ( '<STR_LIT:utf-8>' ) , <EOL> unicode ( pw_hash ) . encode ( '<STR_LIT:utf-8>' ) <EOL> ) , <EOL> pw_hash <EOL> ) </s>
