def set_password(self, new_password): """ Ustawia nowe hasło użytkownikowi :param new_password: :return: """ self.__hashed_password = password_hash(new_password)
def check_password(self, cursor, password): sql = f"""SELECT hashed_password FROM users WHERE email='{self.email}'""" cursor.execute(sql) if cursor.fetchone()[0] == password_hash(password, salt='123'): return True else: return False
def add_to_database(self, database_connection): cursor = database_connection.cursor() self.password = password_hash(self.password) cursor.execute( "INSERT INTO Users(email, password) VALUES (%s, %s) RETURNING user_id;", [self.email, self.password]) self.set_user_id(cursor.fetchone()[0]) cursor.close()
def set_password(self, password): """ Sets password to user - since password is private variable. Uses password_hash() to hash password. :param password: password to be set, string type :return: no return """ self.__hashed_password = password_hash(password)
def set_password(self, password): '''This method allows us to set password of current object user, lenght of the password must be greater or equal than 8 signs.''' while True: if len(password) >= 8: self.__hashed_password = password_hash(password, generate_salt()) break else: password = input( "Password must have 8 signs or more enter another one: ")
def test_pswd_hash_salt_lt_16(self): self.assertEqual(len(password_hash(self.password, )), 16 + 64) self.assertNotIn('?', password_hash(self.password, salt=self.salt1)) self.assertNotIn('-', password_hash(self.password, salt=self.salt1)) self.assertNotIn(';', password_hash(self.password, salt=self.salt1)) self.assertEqual(password_hash(self.password, salt=self.salt1)[0:4],'vf33') self.assertEqual(password_hash(self.password, salt=self.salt1)[9:16], 'aaaaaaa')
def test_pswd_hash_salt_gt_16(self): l = len(self.salt2) self.assertEqual(len(password_hash(self.password, )), 16 + 64) self.assertNotIn('?', password_hash(self.password, salt=self.salt2)) self.assertNotIn('-', password_hash(self.password, salt=self.salt2)) self.assertNotIn(';', password_hash(self.password, salt=self.salt2)) self.assertEqual(password_hash(self.password, salt=self.salt2)[10:15],self.salt2[10:15]) self.assertNotEqual(password_hash(self.password, salt=self.salt2)[16:l], self.salt2[16:l])
def user_and_password(): correct_user_password = User.load_user_by_name_and_pass(ctx.cursor(), results.user_name, results.user_password) if not results.user_password \ and not results.delete_user \ and not results.modify_user \ and not results.users_list: # return 'No argument was added, try to use "-h/--help"' return parser.print_help() elif correct_user_password \ and not results.delete_user \ and not results.modify_user \ and not results.users_list: return "User already exists, maybe you meant to delete '-d' or modify '-e'?" elif results.user_name and results.user_password \ and not correct_user_password \ and not results.delete_user \ and not results.modify_user: add_user() return "User {} was added to the database".format(results.user_name) elif correct_user_password and results.modify_user \ and not results.delete_user: User.update_password(ctx, password_hash(results.new_password, None), results.user_name) # print(results.new_password) # print(password_hash(results.new_password, None)) return "Password successfully changed!" elif correct_user_password and results.delete_user \ and not results.modify_user: User.delete_by_username(ctx.cursor(), results.user_name) return "User {} was deleted".format(results.user_name) elif not results.user_password \ or not results.user_name: return "User password or user name is missing, fill it to use the function" elif correct_user_password and results.users_list: users = User.load_all_users(ctx.cursor()) for user in users: print(user)
def __init__(self, username=None, email=None, password=None): super().__init__() self.username = username self.email = email self.__password = password_hash(password)
def test_exceptions(self): with self.assertRaises(Exception): password_hash() with self.assertRaises(Exception): check_password()
def set_password(self, password, salt=''): if len(password) <= 8: raise Exception("Hasło jest za krótkie") self.__hashed_password = password_hash(password, salt)
def set_password(self, password): self._hashed_password = clcrypto.password_hash(password)
def set_password(self, password): self._hashed_password = password_hash(password) return self._hashed_password
def hashed_password(self, dict_pass_salt): self.__hashed_password = password_hash(dict_pass_salt["password"], dict_pass_salt["salt"])
def password(self, password): if len(password) >= 8: self.__password = password_hash(password)
def set_password(self, password): """Sets hashed password""" self.__hashed_password = password_hash(password)
def set_password(self, password): salt = generate_salt() self.__hashed_password = password_hash(password, salt)
def set_password(self, password, salt): self.__hashed_password = password_hash(password, salt)
def test_pswd_hash_salt_none(self): self.assertEqual(len(password_hash(self.password)), 16 + 64) self.assertNotIn('?', password_hash(self.password)) self.assertNotIn('.', password_hash(self.password)) self.assertNotIn('=', password_hash(self.password))
def set_password(self, password, salt): # ustawia hasło od razu je szyfrując self._hashed_password = password_hash(password, salt)
def set_password(self, new_pasword): self.__hashed_password = password_hash(new_pasword)