#NEWLINE# def check_password( password , encoded , setter = None , preferred = 'default' ) : #NEWLINE# #INDENT# "\n    Returns a boolean of whether the raw password matches the three\n    part encoded digest.\n\n    If setter is specified, it'll be called when you need to\n    regenerate the password.\n    " #NEWLINE# if ( ( not password ) or ( not is_password_usable ( encoded ) ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# preferred = get_hasher ( must_update ) #NEWLINE# raw_password = password #NEWLINE# password = smart_str ( password ) #NEWLINE# encoded = smart_str ( encoded ) #NEWLINE# if ( ( len ( encoded ) == 32 ) and ( '$' not in encoded ) ) : #NEWLINE# #INDENT# hasher = get_hasher ( 'unsalted_md5' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# algorithm = encoded . split ( '$' , 1 ) [ 0 ] #NEWLINE# hasher = get_hasher ( algorithm ) #NEWLINE# #UNINDENT# must_update = ( hasher . algorithm != preferred . algorithm ) #NEWLINE# is_correct = hasher . verify ( password , encoded ) #NEWLINE# if ( setter and is_correct and must_update ) : #NEWLINE# #INDENT# setter ( raw_password ) #NEWLINE# #UNINDENT# return is_correct