Transfer first library files

This commit is contained in:
Achim Rohn
2025-07-27 17:53:07 +02:00
parent e187673510
commit 728cf90236
7 changed files with 196 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
package ersteller_lib
// https://medium.com/@rnp0728/secure-password-hashing-in-go-a-comprehensive-guide-5500e19e7c1f
import "golang.org/x/crypto/bcrypt"
// HashPassword generates a bcrypt hash for the given password.
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
return string(bytes), err
}
// VerifyPassword verifies if the given password matches the stored hash.
func VerifyPassword(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}