From 783531d3c481c065a083be858bb7ee344f0cae39 Mon Sep 17 00:00:00 2001 From: Richard Bowden Date: Sun, 17 Dec 2017 21:50:51 +0000 Subject: [PATCH 1/2] rename files to match package name --- .gitignore | 1 + scramble.go => passwordHash.go | 0 scramble_test.go => passwordHash_test.go | 0 3 files changed, 1 insertion(+) rename scramble.go => passwordHash.go (100%) rename scramble_test.go => passwordHash_test.go (100%) diff --git a/.gitignore b/.gitignore index daf913b..569f6be 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ _testmain.go *.exe *.test *.prof +debug \ No newline at end of file diff --git a/scramble.go b/passwordHash.go similarity index 100% rename from scramble.go rename to passwordHash.go diff --git a/scramble_test.go b/passwordHash_test.go similarity index 100% rename from scramble_test.go rename to passwordHash_test.go From 261590cb6a9c694359cc3f0166934c07abb61819 Mon Sep 17 00:00:00 2001 From: Richard Bowden Date: Sun, 17 Dec 2017 22:39:59 +0000 Subject: [PATCH 2/2] added an interface and default hashser --- passwordHasher.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 passwordHasher.go diff --git a/passwordHasher.go b/passwordHasher.go new file mode 100644 index 0000000..fcb825c --- /dev/null +++ b/passwordHasher.go @@ -0,0 +1,21 @@ +package passwordHash + +import "github.com/richardbowden/passwordHash" + +// PasswordHasher is an interface that describes two basic functions that can be +// used to perform a password encode and validate +type PasswordHasher interface { + Encode(pw1 string, pw2 string) (string, error) + Validate(pw string, hashPackage string) (bool, error) +} + +// DefaultPasswordHasher impliments the PasswordHasher interface which uses passwordHash +type DefaultPasswordHasher struct{} + +func (DefaultPasswordHasher) Encode(pw1 string, pw2 string) (string, error) { + return passwordHash.HashWithDefaults(pw1, pw2) +} + +func (DefaultPasswordHasher) Validate(pw string, hashedPackage string) (bool, error) { + return passwordHash.Validate(pw, hashedPackage) +}