diff --git a/Sources/Vapor/Passwords/AsyncPasswordHasher.swift b/Sources/Vapor/Passwords/AsyncPasswordHasher.swift index e56e0bd46e..df194f34a5 100644 --- a/Sources/Vapor/Passwords/AsyncPasswordHasher.swift +++ b/Sources/Vapor/Passwords/AsyncPasswordHasher.swift @@ -22,7 +22,7 @@ public struct AsyncPasswordHasher { self.eventLoop = eventLoop } - public func hash(_ password: Password) throws -> EventLoopFuture<[UInt8]> + public func hash(_ password: Password) -> EventLoopFuture<[UInt8]> where Password: DataProtocol { let promise = self.eventLoop.makePromise(of: [UInt8].self) @@ -39,7 +39,7 @@ public struct AsyncPasswordHasher { public func verify( _ password: Password, created digest: Digest - ) throws -> EventLoopFuture + ) -> EventLoopFuture where Password: DataProtocol, Digest: DataProtocol { let promise = eventLoop.makePromise(of: Bool.self) @@ -53,14 +53,14 @@ public struct AsyncPasswordHasher { return promise.futureResult } - public func hash(_ password: String) throws -> EventLoopFuture { - try self.hash([UInt8](password.utf8)).map { + public func hash(_ password: String) -> EventLoopFuture { + self.hash([UInt8](password.utf8)).map { String(decoding: $0, as: UTF8.self) } } - public func verify(_ password: String, created digest: String) throws -> EventLoopFuture { - try self.verify( + public func verify(_ password: String, created digest: String) -> EventLoopFuture { + self.verify( [UInt8](password.utf8), created: [UInt8](digest.utf8) ) diff --git a/Tests/VaporTests/PasswordTests.swift b/Tests/VaporTests/PasswordTests.swift index d83ac02d3d..10ffc4fe88 100644 --- a/Tests/VaporTests/PasswordTests.swift +++ b/Tests/VaporTests/PasswordTests.swift @@ -109,18 +109,14 @@ final class PasswordTests: XCTestCase { app.passwords.use(provider) app.get("test") { req -> EventLoopFuture in - return try req.password + return req.password .async .hash("vapor") .flatMap { digest -> EventLoopFuture in - do { - return try req.password - .async - .verify("vapor", created: digest) - } catch { - XCTFail("failed to verify digest", file: file, line: line) - return req.eventLoop.makeFailedFuture(error) - } + return req.password + .async + .verify("vapor", created: digest) + } .map { $0 ? "true" : "false" } }