def register_user(username, password): new_user = { "id": persistence.new_id_to_csv(persistence.USERS_FILE), "username": username, "password": hash_password(password) } persistence.get_users().append(new_user) persistence.export_data("users")
def get_password_hash_for_username(username): users = persistence.get_users() # returns the hashed password for that username try: return [ user["password"] for user in users if user["username"] == username ][0] except IndexError: return ''
def register(data): all_users = persistence.get_users() new_user = {} username = data['username'] if username not in [user['username'] for user in all_users]: # print([username for username in all_users ]) hashed_password = util.hash_password_salt(data['password']) new_user['id'] = persistence.get_new_user_id('id') new_user['username'] = username new_user['password'] = hashed_password all_users.append(new_user) # print(all_users) persistence.write_users(all_users) return {"status": "ok"} else: return {"status": "wrong"}
def login(data): all_users = persistence.get_users() username = data['username'] password = data['password'] if username != "" and password != "" and \ username in [user['username'] for user in all_users]: for user in all_users: if user['username'] == username: if util.verify_psswd(password, user['password']): return { "status": "ok", "user_id": user['id'], "username": username } else: return {"status": "wrong"} else: return {"status": "wrong"}
def user_not_exist(username): users = persistence.get_users() for user in users: if user['username'] == username: return False return True
def get_users(): return persistence.get_users(force=True)
def get_user_id_by_username(username): all_users = persistence.get_users() for user in all_users: if user['username'] == username: return user['id']
def get_user_by_id(id): all_users = persistence.get_users() for user in all_users: if user['id'] == str(id): return user
def get_user(name, password): persistence.clear_cache() all_users = persistence.get_users() for user in all_users: if user['name'] == str(name) and user['password'] == str(password): return user
def get_users(): all_users = persistence.get_users() return all_users