mirror of
https://github.com/jeremyd/ergo.git
synced 2026-07-23 07:38:10 -07:00
Fixing warnings and golint stuff
This commit is contained in:
+8
-4
@@ -11,12 +11,14 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
EmptyPasswordError = errors.New("empty password")
|
||||
// ErrEmptyPassword means that an empty password was given.
|
||||
ErrEmptyPassword = errors.New("empty password")
|
||||
)
|
||||
|
||||
// GenerateEncodedPassword returns an encrypted password, encoded into a string with base64.
|
||||
func GenerateEncodedPassword(passwd string) (encoded string, err error) {
|
||||
if passwd == "" {
|
||||
err = EmptyPasswordError
|
||||
err = ErrEmptyPassword
|
||||
return
|
||||
}
|
||||
bcrypted, err := bcrypt.GenerateFromPassword([]byte(passwd), bcrypt.MinCost)
|
||||
@@ -27,15 +29,17 @@ func GenerateEncodedPassword(passwd string) (encoded string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func DecodePassword(encoded string) (decoded []byte, err error) {
|
||||
// DecodePasswordHash takes a base64-encoded password hash and returns the appropriate bytes.
|
||||
func DecodePasswordHash(encoded string) (decoded []byte, err error) {
|
||||
if encoded == "" {
|
||||
err = EmptyPasswordError
|
||||
err = ErrEmptyPassword
|
||||
return
|
||||
}
|
||||
decoded, err = base64.StdEncoding.DecodeString(encoded)
|
||||
return
|
||||
}
|
||||
|
||||
// ComparePassword compares a given password with the given hash.
|
||||
func ComparePassword(hash, password []byte) error {
|
||||
return bcrypt.CompareHashAndPassword(hash, password)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user