Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #6 from brokenhandsio/master
Browse files Browse the repository at this point in the history
Proposal: Change signature of PasswordVerifier
  • Loading branch information
0xTim authored May 5, 2017
2 parents 5f0b6ec + b2737fc commit d326f4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/Packages
/*.xcodeproj
Package.pins
DerivedData/

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Bits

public protocol PasswordAuthenticatable: Authenticatable {
// MARK: Username / Password
/// Return the user matching the supplied
Expand Down Expand Up @@ -44,7 +46,15 @@ extension PasswordAuthenticatable {


public protocol PasswordVerifier {
func verify(password: String, matchesHash: String) throws -> Bool
func verify(password: Bytes, matches hash: Bytes) throws -> Bool
}

extension PasswordVerifier {
public func verify(password: BytesConvertible, matches hash: BytesConvertible) throws -> Bool {
let password = try password.makeBytes()
let hash = try hash.makeBytes()
return try verify(password: password, matches: hash)
}
}

// MARK: Entity conformance
Expand All @@ -69,8 +79,8 @@ extension PasswordAuthenticatable where Self: Entity {
}

guard try verifier.verify(
password: creds.password,
matchesHash: hash
password: creds.password.makeBytes(),
matches: hash.makeBytes()
) else {
throw AuthenticationError.invalidCredentials
}
Expand Down

0 comments on commit d326f4d

Please sign in to comment.