mirror of
https://github.com/pushbits/server.git
synced 2025-05-16 10:26:31 +02:00
Initialize repository
This commit is contained in:
commit
1d758fcfd0
28 changed files with 1107 additions and 0 deletions
21
authentication/credentials/credentials.go
Normal file
21
authentication/credentials/credentials.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue