Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ability to log in after changing mail #198

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/services/AuthenticationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class AuthenticationService {

if (!electionOrg) return
const passwordMatches = await this.hashService.compareAgainstHash(payload.password, electionOrg.password)

if (!passwordMatches) return
return this.generateTokenFromId(electionOrg.id)
}
Expand Down
7 changes: 5 additions & 2 deletions src/services/ElectionOrganizerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ export class ElectionOrganizerService extends BaseEntityService<ElectionOrganize

const strippedOrganizer = strip(organizerDTO, ['id', 'createdAt', 'updatedAt'])
if (strippedOrganizer?.password) {
const hashedPassword = await encryptionService.hash(organizerDTO.password)
strippedOrganizer.password = hashedPassword
const storedPassword = (await this.getElectionOrganizerById(id)).password
if (storedPassword !== strippedOrganizer.password) {
const hashedPassword = await encryptionService.hash(organizerDTO.password)
Comment on lines +82 to +83
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This in-equality check will always be satisfied.
As the storedPassword can never be equal to the password provided in the request(assuming we never provide the password to the frontend....), as this is either a new one (in plain text, not hashed) or undefined.

To fix this, check if there is a password provided, not undefined and not empty string + (@spiftire is creating validation). Then just hash that password and update, it is not possible to perform an equality as a new hash would always be different, even with the same input :D

strippedOrganizer.password = hashedPassword
}
}

if (!isEmailValid(strippedOrganizer!.email)) {
Expand Down