def add_user(usr_id, name, email, screen_name, password): '''Creates a new row in the user table with the passed in parameters and the current time.''' salt = auth.normalize(os.urandom(32)) pass_hash = auth.saltedhash_hex(password, salt) con = db.connections.get_con() cur = db.DictCursor(con) cur.callproc('create_user', (usr_id, name, email, screen_name, pass_hash, salt)) cur.close() db.connections.release_con(con) logger.writeln('added user: ', (usr_id, name, email, screen_name, pass_hash, salt))
def verify_passwd(req, email, password): '''this takes the user_name (ie the string the user uses to log-in with) if and the plain text password. The password is hashed if there is a user by the name passed in then the hashes of the passwords are compared. If they match it returns True else it returns False.''' user_dict = get_user_byemail(req, email) #get the user_dict from the database if user_dict: pass_hash = auth.saltedhash_hex(password, user_dict['salt']) else: return False, dict() #if the user_dict actually has information in it check to see if the passwords are the same if user_dict and user_dict.has_key('pass_hash') and pass_hash == user_dict['pass_hash']: return True, user_dict #if they are return true and the user dictionary else: return False, dict() #else return false and an empty dictionary
def add_user(srv, usr_id, name, email, password): '''Creates a new row in the user table with the passed in parameters and the current time.''' salt = auth.normalize(os.urandom(32)) pass_hash = auth.saltedhash_hex(password, salt) srv.users[usr_id] = { 'usr_id': usr_id, 'name':name, 'email':email, 'pass_hash':pass_hash, 'salt':salt, 'last_login':time.strftime('%Y-%m-%d %H:%M:%S'), 'creation':time.strftime('%Y-%m-%d %H:%M:%S'), } srv.users_email[email] = usr_id return dict(srv.users[usr_id])