Skip to content

Instantly share code, notes, and snippets.

@jasonhancock
Created November 29, 2018 19:28
Show Gist options
  • Save jasonhancock/ba501036a03e6f3f33d6d749bab8c767 to your computer and use it in GitHub Desktop.
Save jasonhancock/ba501036a03e6f3f33d6d749bab8c767 to your computer and use it in GitHub Desktop.
bcrypt time cost at various difficulty factors
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