Пример #1
0
 def attempt_login(cls, username, password):
     user = UserService.get_user(username)
     if not user:
         return None
     hashed_pass = hash_password(password, user.salt)
     if hashed_pass != user.password:
         return None
     session = SessionService.get_session_by_user(user)
     if session:
         return session.token
     token = gen_token()
     SessionService.create_session(user, token)
     return token
Пример #2
0
 def create_user(cls, username, password, first_name, last_name,
                 institution, email):
     salt = gen_salt()
     hashed_pass = hash_password(password, salt)
     user = User(username=username,
                 password=hashed_pass,
                 salt=salt,
                 first_name=first_name,
                 last_name=last_name,
                 institution=institution,
                 email=email)
     user.save()
     return user
Пример #3
0
 def attempt_login(cls, username, password):
     user = UserService.get_user(username)
     if not user:
         return None
     hashed_pass = hash_password(password, user.salt)
     if hashed_pass != user.password:
         return None
     session = SessionService.get_session_by_user(user)
     if session:
         return session.token
     token = gen_token()
     SessionService.create_session(user, token)
     return token
Пример #4
0
 def create_user(cls, username, password, first_name, last_name, institution, email):
     salt = gen_salt()
     hashed_pass = hash_password(password, salt)
     user = User(
         username=username,
         password=hashed_pass,
         salt=salt,
         first_name=first_name,
         last_name=last_name,
         institution=institution,
         email=email,
     )
     user.save()
     return user
Пример #5
0
 def test_hashes_to_correct_value(self):
     salt = "$2a$12$DG39IJLyK/8DQ18Zz/GclO"
     password = '******'
     hashed_pass = hash_password(password, salt)
     assert hashed_pass == \
         "$2a$12$DG39IJLyK/8DQ18Zz/GclOARDSrOQSZNQ8VRNPYGWiSAsjX380KHK"
Пример #6
0
 def test_hashes_to_correct_value(self):
     salt = "$2a$12$DG39IJLyK/8DQ18Zz/GclO"
     password = '******'
     hashed_pass = hash_password(password, salt)
     assert hashed_pass == \
         "$2a$12$DG39IJLyK/8DQ18Zz/GclOARDSrOQSZNQ8VRNPYGWiSAsjX380KHK"