Browse Source
Merge pull request #104 from vernu/improve-password-validation
improve password validation logic
pull/105/head
Israel Abebe
8 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
4 additions and
2 deletions
-
api/src/auth/auth.service.ts
|
|
@ -251,6 +251,8 @@ export class AuthService { |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.validatePassword(input.newPassword) |
|
|
|
|
|
|
|
|
const hashedPassword = await bcrypt.hash(input.newPassword, 10) |
|
|
const hashedPassword = await bcrypt.hash(input.newPassword, 10) |
|
|
userToUpdate.password = hashedPassword |
|
|
userToUpdate.password = hashedPassword |
|
|
await userToUpdate.save() |
|
|
await userToUpdate.save() |
|
|
@ -450,9 +452,9 @@ export class AuthService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
async validatePassword(password: string) { |
|
|
async validatePassword(password: string) { |
|
|
if (password.length < 6) { |
|
|
|
|
|
|
|
|
if (password.length < 6 || password.length > 128) { |
|
|
throw new HttpException( |
|
|
throw new HttpException( |
|
|
{ error: 'Password must be at least 6 characters' }, |
|
|
|
|
|
|
|
|
{ error: 'Password must be between 6 and 128 characters' }, |
|
|
HttpStatus.BAD_REQUEST, |
|
|
HttpStatus.BAD_REQUEST, |
|
|
) |
|
|
) |
|
|
} |
|
|
} |
|
|
|