Initialize repository

This commit is contained in:
eikendev 2020-07-26 00:28:38 +02:00
commit 1d758fcfd0
No known key found for this signature in database
GPG key ID: A1BDB1B28C8EF694
28 changed files with 1107 additions and 0 deletions

View file

@ -0,0 +1,21 @@
package credentials
import "golang.org/x/crypto/bcrypt"
// CreatePassword returns a hashed version of the given password.
// TODO: Make strength configurable.
func CreatePassword(pw string) []byte {
strength := 12
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(pw), strength)
if err != nil {
panic(err)
}
return hashedPassword
}
// ComparePassword compares a hashed password with its possible plaintext equivalent.
func ComparePassword(hashedPassword, password []byte) bool {
return bcrypt.CompareHashAndPassword(hashedPassword, password) == nil
}