mirror of
https://github.com/pushbits/server.git
synced 2025-05-11 16:07:04 +02:00
Make hashing parameters configurable
This commit is contained in:
parent
c0ac5c3d16
commit
ba0306f384
8 changed files with 86 additions and 37 deletions
31
authentication/credentials/password.go
Normal file
31
authentication/credentials/password.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package credentials
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/alexedwards/argon2id"
|
||||
)
|
||||
|
||||
// CreatePasswordHash returns a hashed version of the given password.
|
||||
func (m *Manager) CreatePasswordHash(password string) []byte {
|
||||
hash, err := argon2id.CreateHash(password, m.argon2Params)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return []byte(hash)
|
||||
}
|
||||
|
||||
// ComparePassword compares a hashed password with its possible plaintext equivalent.
|
||||
func ComparePassword(hash, password []byte) bool {
|
||||
match, err := argon2id.ComparePasswordAndHash(string(password), string(hash))
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return false
|
||||
}
|
||||
|
||||
return match
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue