diff options
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/PasswordHash.ts | 17 |
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 @@ | |||
1 | import User from '#app/Models/User' | 1 | import User from '#app/Models/User'; |
2 | import hash from '@adonisjs/core/services/hash' | 2 | import hash from '@adonisjs/core/services/hash'; |
3 | 3 | ||
4 | export async function handleVerifyAndReHash(user: User, passwordToTest: string): Promise<boolean> { | 4 | export 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 | } |