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

bcrypt: add easy bcrypt example #99

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions bcrypt/bcrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,14 @@ func TestNoSideEffectsFromCompare(t *testing.T) {
t.Errorf("got=%q want=%q", got, want)
}
}

func ExampleBcrypting() {
password := []byte("mypassword")
securedPassword, err := GenerateFromPassword(password, DefaultCost)

Choose a reason for hiding this comment

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

Maybe you can rename it hashedPassword, like the first param of CompareHashAndPassword

Copy link
Author

Choose a reason for hiding this comment

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

It's salted and hashed. As saltedHashedPassword was a little to long for me, I called it secured.
Does that make sense?

Copy link
Author

Choose a reason for hiding this comment

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

Ping

Choose a reason for hiding this comment

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

Ok. But securedPassword comes from nowhere. But it's clear to me.
I try to improve.
But you're right. 👍

if err != nil {
panic(err)
}

fmt.Println(CompareHashAndPassword(securedPassword, password))
// Output: <nil>
}