Skip to content

Commit

Permalink
bcrypt: Externalize example to separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Gohr committed Mar 9, 2020
1 parent 9bf4791 commit 4cac054
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
11 changes: 0 additions & 11 deletions bcrypt/bcrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,3 @@ func TestNoSideEffectsFromCompare(t *testing.T) {
t.Errorf("got=%q want=%q", got, want)
}
}

func ExampleBcrypting() {
password := []byte("mypassword")
securedPassword, err := GenerateFromPassword(password, DefaultCost)
if err != nil {
panic(err)
}

fmt.Println(CompareHashAndPassword(securedPassword, password))
// Output: <nil>
}
17 changes: 17 additions & 0 deletions bcrypt/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package bcrypt_test

import (
"fmt"
"golang.org/x/crypto/bcrypt"
)

func ExampleGenerateFromPassword() {
password := []byte("mypassword")
securedPassword, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost)
if err != nil {
panic(err)
}

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

0 comments on commit 4cac054

Please sign in to comment.