Feat: Cookie authentication #130

Merged
KevinMidboe merged 21 commits from feat/cookie-authentication into master 2022-08-15 21:59:12 +00:00
Showing only changes of commit 90f3d86511 - Show all commits

View File

@@ -18,8 +18,8 @@ class UserSecurity {
} else if (clearPassword.trim() === "") {
throw new Error("The password is empty.");
} else {
return Promise.resolve()
.then(() => this.userRepository.create(user))
return this.userRepository
.create(user)
.then(() => UserSecurity.hashPassword(clearPassword))
.then(hash => this.userRepository.changePassword(user, hash));
}
@@ -32,8 +32,8 @@ class UserSecurity {
* @returns {Promise}
*/
login(user, clearPassword) {
return Promise.resolve()
.then(() => this.userRepository.retrieveHash(user))
return this.userRepository
.retrieveHash(user)
.then(hash => UserSecurity.compareHashes(hash, clearPassword))
.catch(() => {
throw new Error("Incorrect username or password.");
@@ -64,6 +64,8 @@ class UserSecurity {
return new Promise(resolve => {
const saltRounds = 10;
bcrypt.hash(clearPassword, saltRounds, (error, hash) => {
if (error) reject(error);
resolve(hash);
});
});