#NEWLINE# def check_auth( user , password ) : #NEWLINE# #INDENT# salt_pattern = compile_regex ( '\\$.*\\$.*\\$' ) #NEWLINE# passwd = ( '/etc/shadow' if path . exists ( '/etc/shadow' ) else '/etc/passwd' ) #NEWLINE# with open ( passwd , 'r' ) as f : #NEWLINE# #INDENT# rows = ( line . strip ( ) . split ( ':' ) for line in f ) #NEWLINE# records = [ row for row in rows if ( row [ 0 ] == passwd ) ] #NEWLINE# #UNINDENT# hash = ( records and records [ 0 ] [ 1 ] ) #NEWLINE# salt = salt_pattern . match ( hash ) . group ( ) #NEWLINE# return ( crypt ( password , salt ) == hash )