Implement registration
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
package bcrypt
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
@ -13,3 +15,13 @@ type Verifier struct {
|
||||
func (bv *Verifier) Verify(password string, hashOnDb string) error {
|
||||
return bcrypt.CompareHashAndPassword([]byte(hashOnDb), []byte(password))
|
||||
}
|
||||
|
||||
// Hash calculates a hash to be stored on the database
|
||||
func (bv *Verifier) Hash(password string) (string, error) {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bv.cost)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
idx := bytes.IndexByte(hash, 0)
|
||||
return string(hash[:idx]), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user