aboutsummaryrefslogtreecommitdiffstats
path: root/helpers/PasswordHash.ts
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/PasswordHash.ts')
-rw-r--r--helpers/PasswordHash.ts17
1 files changed, 10 insertions, 7 deletions
diff --git a/helpers/PasswordHash.ts b/helpers/PasswordHash.ts
index 5c73195..300186d 100644
--- a/helpers/PasswordHash.ts
+++ b/helpers/PasswordHash.ts
@@ -1,14 +1,17 @@
1import User from '#app/Models/User' 1import User from '#app/Models/User';
2import hash from '@adonisjs/core/services/hash' 2import hash from '@adonisjs/core/services/hash';
3 3
4export async function handleVerifyAndReHash(user: User, passwordToTest: string): Promise<boolean> { 4export async function handleVerifyAndReHash(
5 user: User,
6 passwordToTest: string,
7): Promise<boolean> {
5 // Verify password 8 // Verify password
6 const usesLegacyHasher = /^\$2[aby]/.test(user.password) 9 const usesLegacyHasher = /^\$2[aby]/.test(user.password);
7 let isMatchedPassword = false 10 let isMatchedPassword = false;
8 11
9 isMatchedPassword = await (usesLegacyHasher 12 isMatchedPassword = await (usesLegacyHasher
10 ? hash.use('legacy').verify(user.password, passwordToTest) 13 ? hash.use('legacy').verify(user.password, passwordToTest)
11 : hash.verify(user.password, passwordToTest)) 14 : hash.verify(user.password, passwordToTest));
12 15
13 // TODO: For some reason this is not working (user can't login after re-hashing) 16 // TODO: For some reason this is not working (user can't login after re-hashing)
14 // rehash user password 17 // rehash user password
@@ -17,5 +20,5 @@ export async function handleVerifyAndReHash(user: User, passwordToTest: string):
17 // await user.save(); 20 // await user.save();
18 // } 21 // }
19 22
20 return isMatchedPassword 23 return isMatchedPassword;
21} 24}