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