From 175c6a40da9b6f0e7f61950734ca62297f5b3881 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Tue, 25 Apr 2017 08:41:42 +0100 Subject: [PATCH 1/2] Update signature of PasswordVerifier --- .gitignore | 1 + .../Authenticatable/PasswordAuthenticatable.swift | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index eb33e53..9f16ab7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /Packages /*.xcodeproj Package.pins +DerivedData/ diff --git a/Sources/Authentication/Authenticatable/PasswordAuthenticatable.swift b/Sources/Authentication/Authenticatable/PasswordAuthenticatable.swift index 215c310..c26c1bc 100644 --- a/Sources/Authentication/Authenticatable/PasswordAuthenticatable.swift +++ b/Sources/Authentication/Authenticatable/PasswordAuthenticatable.swift @@ -44,7 +44,7 @@ extension PasswordAuthenticatable { public protocol PasswordVerifier { - func verify(password: String, matchesHash: String) throws -> Bool + func verify(password: String, matches hash: String) throws -> Bool } // MARK: Entity conformance @@ -70,7 +70,7 @@ extension PasswordAuthenticatable where Self: Entity { guard try verifier.verify( password: creds.password, - matchesHash: hash + matches: hash ) else { throw AuthenticationError.invalidCredentials } From b2737fc2da286d32829b0c59ff164bdf92378198 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Tue, 25 Apr 2017 20:44:26 +0100 Subject: [PATCH 2/2] Update PasswordVerifier to use Bytes instead of a String as per PR comments --- .../PasswordAuthenticatable.swift | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Sources/Authentication/Authenticatable/PasswordAuthenticatable.swift b/Sources/Authentication/Authenticatable/PasswordAuthenticatable.swift index c26c1bc..fa5981d 100644 --- a/Sources/Authentication/Authenticatable/PasswordAuthenticatable.swift +++ b/Sources/Authentication/Authenticatable/PasswordAuthenticatable.swift @@ -1,3 +1,5 @@ +import Bits + public protocol PasswordAuthenticatable: Authenticatable { // MARK: Username / Password /// Return the user matching the supplied @@ -44,7 +46,15 @@ extension PasswordAuthenticatable { public protocol PasswordVerifier { - func verify(password: String, matches hash: 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 @@ -69,8 +79,8 @@ extension PasswordAuthenticatable where Self: Entity { } guard try verifier.verify( - password: creds.password, - matches: hash + password: creds.password.makeBytes(), + matches: hash.makeBytes() ) else { throw AuthenticationError.invalidCredentials }