 import Foundation
 import Auth
 import Hash
+import BCrypt
 
 final class User: Model {
     var id: Node?

            let username = apiKey.id
            let password = apiKey.secret
            
            let hashedPassword = try Hash.make(Hash.Method.sha512, Array(password.utf8))
            var user = User(username: username, password: String(describing: (hashedPassword, encoding: String.Encoding.utf8)))
            
            let tempUser = try User.query().filter("username", username).first()
            

            user = try User.query().filter("access_token", accessToken.string).first()
            // process here
        case let apiKey as APIKey:
            user = try User.query().filter("username", apiKey.id).first()
            
            guard user != nil else {
                throw UserError.noSuchUser
            }
            
            let matched = try BCrypt.verify(password: apiKey.secret, matchesHash: (user?.password)!)
            if matched == false {
                    throw AuthError.invalidCredentials
            }
            
        default:
            throw AuthError.invalidCredentials
        }
        
        return user!
    }
    
    static func register(credentials: Credentials) throws -> Auth.User {
