aboutsummaryrefslogtreecommitdiff
path: root/ssha.go
diff options
context:
space:
mode:
Diffstat (limited to 'ssha.go')
-rw-r--r--ssha.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/ssha.go b/ssha.go
index 202ce12..cca51c7 100644
--- a/ssha.go
+++ b/ssha.go
@@ -2,6 +2,8 @@ package main
import (
"errors"
+ "regexp"
+ "strings"
"github.com/jsimonetti/pwscheme/ssha"
"github.com/jsimonetti/pwscheme/ssha256"
@@ -14,6 +16,8 @@ const (
SSHA512 = "{SSHA512}"
)
+var scheme = regexp.MustCompile(`^{([0-9a-zA-Z]+)}`)
+
// Encode encodes the string to ssha512
func SSHAEncode(rawPassPhrase string) (string, error) {
return ssha512.Generate(rawPassPhrase, 16)
@@ -21,7 +25,9 @@ func SSHAEncode(rawPassPhrase string) (string, error) {
// Matches matches the encoded password and the raw password
func SSHAMatches(encodedPassPhrase string, rawPassPhrase string) (bool, error) {
- hashType, err := determineHashType(encodedPassPhrase)
+ cleanEncodedPass := uppercaseScheme(encodedPassPhrase)
+
+ hashType, err := determineHashType(cleanEncodedPass)
if err != nil {
return false, errors.New("invalid password hash stored")
}
@@ -51,3 +57,9 @@ func determineHashType(hash string) (string, error) {
return "", errors.New("no valid hash found")
}
+
+func uppercaseScheme(hash string) string {
+ return scheme.ReplaceAllStringFunc(hash, func(w string) string {
+ return strings.ToUpper(w)
+ })
+}