Пример #1
0
def authenticate(email, password):
    from database import bcrypt
    user = DbUser.query.filter_by(email=email).first()
    if user is not None:
        if user.user_authorized and bcrypt.check_password_hash(
                user.password, password):
            return True
    return False
Пример #2
0
 def login(self, password_attempt):
     if bcrypt.check_password_hash(self.password_hash,
                                   self.password_salt + password_attempt):
         session['user_id'] = self.id
         session['username'] = self.username
         session['admin'] = self.isAdmin()
         return True
     else:
         return False
Пример #3
0
def login():
    req = request.json
    auth = request.authorization
    user = User.query.filter_by(username=req["username"]).first()
    if user and bcrypt.check_password_hash(user.password, req["password"]):
        token = jwt.encode({'id': user.id, 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=60)}, os.getenv("SECRET"))
        return jsonify({'token' : token.decode("ascii")})
    else:
        return make_response("Sorry, invalid credentials", 401)
Пример #4
0
 def is_correct_password(self, plaintext):
     return bcrypt.check_password_hash(self._password, plaintext)