def login_user(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] user = UserModel.find_by_username(username) try: #if user and safe_str_cmp(password, user.password): if user and Utils.check_hashed_password(password, user.password): session['username'] = user.username if user.username in current_app.config.get('ADMIN', '').split(','): session['admin'] = True else: session['admin'] = None return redirect(url_for("webmodels.index")) else: session['username'] = None session['admin'] = None return "Invalid credentials! please try again." except: session['username'] = None session['admin'] = None return "Invalid credentials! please try again." return render_template("users/login.html")
def authenticate(username, password): user = UserModel.find_by_username(username) # PostgrsqlDB User Model userDynamoDB = UserModelDynamoDB.find_by_username( username) # aws Dynamo DB User Model # user = username_mapping.get(username, None) if userDynamoDB and userDynamoDB.password == password: return userDynamoDB
def authenticate(username, password): user = UserModel.find_by_username(username) print("coba ya") if user and safe_str_cmp( user.password, password ): # this is simple way for not using safe_str_cmp"if user and user.password == password :"******"bisa nih") return user
def authenticate(username, password): #.get() gets values of te key 'username'; useful for setting a default value #username_mapping['username'] <-- similar to .get without having a default #user = username_mapping.get(username, None) #replacing userid_mapping with database user = UserModel.find_by_username(username) if user and safe_str_cmp(user.password, password): return user
def authenticate( username, password ): ## This is used at the beginning that is when authenticating initially #user=username_mapping.get(username,None) # if there is no key for this username, it would return None user = UserModel.find_by_username(username) if user and safe_str_cmp(user.password, password): #safe_str_cmp(a,b) takes care of different encoding schemes used by a and b and compares them return user
def authenticate(username, password): # user = username_mapping.get(username) # .get will return a value from a dictionary, and "None" is a default value, if # there is no user returned user = UserModel.find_by_username(username) if user and safe_str_cmp( user.password, password): # was before: user.password == password: return user
def test_register_user(self): with self.app() as client: with self.app_context(): response = client.post('/register', data={ 'username': '******', 'password': '******' }) self.assertEqual(response.status_code, 201) self.assertIsNotNone(UserModel.find_by_username('test')) self.assertDictEqual({'message': 'User created successfully.'}, json.loads(response.data))
def register_user(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] #email = request.form['email'] if UserModel.find_by_username(username): return "Username already exists! Try with another name." else: hashed_password=Utils.hash_password(password) user = UserSchema().load({"username":username, "password":hashed_password}) user.save_to_db() session['username'] = user.username return redirect(url_for("webmodels.index")) return render_template("users/register.html")
def authenticate(username, password): user = UserModel.find_by_username( username) #using the Class.method(argument) if user and safe_str_cmp(user.password, password): return user
def authenticate(username, password): # user = username_mapping.get(username, None) user = UserModel.find_by_username(username) if user is not None and safe_str_cmp(user.password, password): return user
def authenticate(username, password): user = UserModel.find_by_username(username) if user and user.password == password: return user
def authenticate(username, password): user = UserModel.find_by_username(username) print(f'I am calling in authentication of {username}') print(user) if user and user.password == password: return user
def authenticate(username, password): user = UserModel.find_by_username(username) if user and bcrypt.checkpw(password.encode('utf-8'), user.password): return user
def authenticate(username, password): user = UserModel.find_by_username(username) if user and safe_str_cmp( user.password, password): # safer way to compare strings in different encodings return user
def authenticate(username, password): user = UserModel.find_by_username(username) if user and safe_str_cmp(user.password, password): return user # Everything is alright. So generate a JWT token
def authenticate(username, password): # getting username from database user = UserModel.find_by_username(username) if user and safe_str_cmp(user.password, password): return user
def authenticate(username,password): user = UserModel.find_by_username(username) # in this case, we are using the Model, not the Resource if user and safe_str_cmp(user.password, password): # to avoid problems in different characters sets or python version return user
def authenticate(username, password): user = UserModel.find_by_username(username) if user and safe_str_cmp( user.password, password): # safe_str_cmp() helps in comparing string safely return user
def authenticate(username, password): user = UserModel.find_by_username( username) #if username_mapping finds nothing, we return None if user and safe_str_cmp(user.password, password): return user
def authenticate(username, password): user = UserModel.find_by_username( username) # using get we can set default value if user and safe_str_cmp(user.password, password): return user
def authenticate(username, password): user = UserModel.find_by_username(username) # print(f'username: {username}, password: {password}') # if user and safe_str_cmp(user.password, password): if user and user.password == password: return user
def authenticate(username: str, password: str) -> Optional[UserModel]: user = UserModel.find_by_username(username) if user and safe_str_cmp(password.encode('utf-8'), user.password.encode('utf-8')): return user else: return None
def authenticate(username, password): user = UserModel.find_by_username(username) if user and safe_str_cmp(user.password, password): return user
def authenticate(username, password): # if no user found return none user = UserModel.find_by_username(username) # safer way of comparing strings, taking care of any encoding problems if user and safe_str_cmp(user.password, password): return user