Created
November 29, 2018 19:28
-
-
Save jasonhancock/ba501036a03e6f3f33d6d749bab8c767 to your computer and use it in GitHub Desktop.
bcrypt time cost at various difficulty factors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"time" | |
"golang.org/x/crypto/bcrypt" | |
) | |
const password = "somePassword" | |
func main() { | |
for i := 4; i <= 17; i++ { | |
start := time.Now() | |
_, err := hashPassword(password, i) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("%2d %.03f\n", i, time.Since(start).Seconds()) | |
} | |
} | |
// hashPassword bcrypts a password | |
func hashPassword(pass string, cost int) ([]byte, error) { | |
return bcrypt.GenerateFromPassword([]byte(pass), cost) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment