Chapter 18: Basic Authentication

After following the instructions down through the end of the Basic Authentication section (through to page 298), when I use RESTed to attempt to create content, I get the following response:

    "error": true,
    "reason": "No BCrypt revision information found"

I have extended my User model with BasicAuthenticatable, and I have added this to my content controller’s boot(router:):

    let basicAuthMiddleware = User.basicAuthMiddleware(using: BCryptDigest())
    let guardAuthMiddleware = User.guardAuthMiddleware()
    let protected = noteRoutes.grouped(basicAuthMiddleware, guardAuthMiddleware) create)

In configure.swift, I have imported Authentication and added:
try services.register(AuthenticationProvider())

Lastly, I have imported Authentication to both my User model and my content controller files.

Does anyone see what I’ve missed?


In case anyone else is having the same problem, I inserted my user directly into my database and did not bcrypt the password. Once I went to, and updated my user with the bcrypt version of the password, this error went away and all worked correctly.

1 Like

@axlroach Thank you for sharing the solution - much appreciated!

Just to elaborate a little on axlroach, I just hit the same issue and discovered why that happen: I had previously created users without hashing the password. So when I tried to authenticate, the error “No BCrypt revision information found” was returned, meaning “the password is not hashed”.

Solution: make sure the user’s records in the database are properly hashed. In my case, I wrote a simple “setupDummyData” function to populate the database, which entered users with a hashed password. After nuking the database (or just fix the issue manually as axlroach points out), it all should be working fine.

I hope this helps.

@tciuro Thank you for sharing this - much appreciated!