Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncryptPassword ¶
EncryptPassword encrypt password, pbkdf2, salt = uuid, with 4096 iterations, keyLen= 32, sha256 It returns an error when the standard library rejects the parameters (only possible in FIPS 140 enforcement mode); never use the returned string when err is not nil.
Example ¶
ExampleEncryptPassword hashes a password with a per-user salt. Store the salt next to the hash; to check a login, hash the entered password with the same salt and compare the two strings.
package main
import (
"fmt"
"github.com/phcp-tech/common-library-golang/encrypt"
)
func main() {
stored, err := encrypt.EncryptPassword("password", "salt")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(stored)
same, _ := encrypt.EncryptPassword("password", "salt")
fmt.Println(same == stored)
wrong, _ := encrypt.EncryptPassword("wrong", "salt")
fmt.Println(wrong == stored)
}
Output: xeR41ZKIyEGqUw22hFxMjZYok6ABzk4RpJY4c6qYE0o= true false
Types ¶
This section is empty.