Skip to content

Commit

Permalink
bcrypt: Add copyright header. Refactor storedPassword. Make usage of …
Browse files Browse the repository at this point in the history
…CompareHashAndPassword more clear
  • Loading branch information
Lars Gohr committed Mar 20, 2020
1 parent 4cac054 commit f6acff4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions bcrypt/example_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package bcrypt_test

import (
Expand All @@ -7,11 +11,13 @@ import (

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

fmt.Println(bcrypt.CompareHashAndPassword(securedPassword, password))
if err := bcrypt.CompareHashAndPassword(storedPassword, password); err != nil {
log.Fatal("invalid password!")
}
// Output: <nil>
}

0 comments on commit f6acff4

Please sign in to comment.