Skip to content

Add VerifyPassword to API #1272

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

Closed

Conversation

tylercloke
Copy link
Contributor

It takes in an email and plain text password to verify. If it fails to find a password stored for email, it returns not_found. If it finds the password hash stored but that hash doesn't match the password passed via the API, it returns verified = false, else it returns verified = true.

Will have some conflicts with #1271 so would prefer to get that one merged first.

Happy to chat about whether or not people think the Dex password API should be doing this but it gives a nice, programmatic way to build additional functionality on top of the API (like having a user verify their password before updating it) that would otherwise be challenging.

It takes in an email and plain text password to verify. If it fails to find a password stored for email, it returns not_found. If it finds the password hash stored but that hash doesn't match the password passed via the API, it returns verified = false, else it returns verified = true.
Copy link
Contributor

@srenatus srenatus left a comment

Choose a reason for hiding this comment

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

I don't think we've got a clear direction on how to evolve the gRPC API of Dex -- but regardless of that, I think this is a useful, and conservative, addition.

Some nitpicks from my side inline 👇

NotFound: false,
}

if err := bcrypt.CompareHashAndPassword(password.Hash, []byte(req.Password)); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think, would it make sense to inspect the err return here? From the code, it'll return bcrypt.ErrMismatchedHashAndPassword if the passwords don't match; but there's other error returns that indicate different failures: here and here.

I'd propose something along the lines of

if err := bcrypt.CompareHashAndPassword(password.Hash, []byte(req.Password)); err != nil {
	if err == bcrypt.ErrMismatchedHashAndPassword {
		resp.Verified = false
		return resp, nil
	}
	return nil, err
}

There might be some further simplifications around those three returns, so, just illustrating what I had in mind.

}

resp := &api.VerifyPasswordResp{
NotFound: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] It's ok to be explicit, but this is equivalent to

resp := &api.VerifyPasswordResp{}

❓ It might be easier to reason about what's happening downward from here if each return declared its own &api.VerifyPasswordResp{}?

}

if req.Password == "" {
return nil, errors.New("no passwored to verify supplied")
Copy link
Contributor

Choose a reason for hiding this comment

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

[typo] s/passwored/password/

@ericchiang
Copy link
Contributor

Sorry for the delay.

Not returning password hashes was an intentional design and I really don't like the idea of making them exportable. What's the use case?

@ericchiang
Copy link
Contributor

Woops, looking closer at this and realized it's not returning the password.

I really don't want dex to add more user management features. v1 went crazy with this and I think it's a good lesson. User management is a product in itself, dex is just a shim.

@srenatus
Copy link
Contributor

I really don't want dex to add more user management features. v1 went crazy with this and I think it's a good lesson. User management is a product in itself, dex is just a shim.

Same as with #1271; this addition would let us check our (local) users' passwords without screenscraping a web login 😅 -- but I'd still maintain that #1020, i.e. reversing the connecting, having our service provide the user mgmt, and dex providing the web login, would be better.

@srenatus
Copy link
Contributor

#1486 has updated this, and has just been merged. 🎉

@srenatus srenatus closed this Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants