Implement registration

This commit is contained in:
2016-12-20 15:26:31 +01:00
parent b9d428d386
commit a71afaf6b9
4 changed files with 42 additions and 1 deletions

View File

@ -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
}