repositorypackage
0.0.0-20241212091436-92b031239b7d
Repository: https://github.com/sunnjek/identity.git
Documentation: pkg.go.dev
# README
identity
Go library implementing the ASP.NET Core identity password hashing algorithm
Install
go get -u github.com/SuNNjek/identity
Usage
Generate new password
package example
import (
"github.com/SuNNjek/identity"
)
func main() {
password := "my password"
// Generate new random salt
salt, _ := identity.GenerateSalt(identity.DefaultSaltLength)
// Hash the password using the default parameters
hash := identity.HashPasswordV3(
[]byte(password),
salt,
identity.DefaultHashAlgorithm,
identity.DefaultIterations,
identity.DefaultNumBytes)
// ...
}
Verify existing password hash
package example
import (
"github.com/SuNNjek/identity"
)
func main() {
// Placeholder, replace with your logic to retrieve password hash
hashedPassword := getPasswordHash()
enteredPassword := "my password"
// Verify the entered password against the hashed one
passwordsMatch := identity.Verify(hashedPassword, []byte(enteredPassword))
// ...
}