-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from josephspurrier/usercase-branch
Usecase branch
- Loading branch information
Showing
30 changed files
with
1,270 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package domain | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
var ( | ||
// ErrPasswordHash is when a password hash operation fails. | ||
ErrPasswordHash = errors.New("Password hash failed.") | ||
) | ||
|
||
// Passhash represents a password hashing system. | ||
type Passhash struct{} | ||
|
||
// PasshashCase represents a service for managing hashed passwords. | ||
type PasshashCase interface { | ||
Hash(password string) (string, error) | ||
Match(hash, password string) bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package passhash | ||
|
||
// Item represents a password hashing system. | ||
type Item struct{} | ||
|
||
// Hash returns a hashed string and an error. | ||
func (s *Item) Hash(password string) (string, error) { | ||
return HashString(password) | ||
} | ||
|
||
// Match returns true if the hash matches the password. | ||
func (s *Item) Match(hash, password string) bool { | ||
return MatchString(hash, password) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Package passhash provides password hashing functionality using bcrypt. | ||
package passhash | ||
|
||
import ( | ||
"golang.org/x/crypto/bcrypt" | ||
) | ||
|
||
// HashString returns a hashed string and an error. | ||
func HashString(password string) (string, error) { | ||
key, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return string(key), nil | ||
} | ||
|
||
// HashBytes returns a hashed byte array and an error. | ||
func HashBytes(password []byte) ([]byte, error) { | ||
key, err := bcrypt.GenerateFromPassword(password, bcrypt.DefaultCost) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return key, nil | ||
} | ||
|
||
// MatchString returns true if the hash matches the password. | ||
func MatchString(hash, password string) bool { | ||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) | ||
if err == nil { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
// MatchBytes returns true if the hash matches the password. | ||
func MatchBytes(hash, password []byte) bool { | ||
err := bcrypt.CompareHashAndPassword(hash, []byte(password)) | ||
if err == nil { | ||
return true | ||
} | ||
|
||
return false | ||
} |
Oops, something went wrong.