Right now I'm using passportjs (local) for authentication on my site, but the username field is case sensitive, is there a way to change this? I thought about making the username all lowercase at the moment of registration, but that doesn't seem like a very efficient choice and still doesn't let me make log in case insensitive.
router.post("/login", middleware.isNotLoggedIn, passport.authenticate("local", {
successRedirect: "",
failureRedirect: "/login"
}), function(req, res){
res.redirect("back");
});
The local authentication strategy authenticates users using a username and password. The strategy requires a verify callback, which accepts these credentials and calls done providing a user.
To sum it up, passport. serializeUser() saves the user inside the session which was earlier created by express-session middleware. Once the user is saved inside the session, the session itself also will get stored inside the database (only if we opt to).
Strategies are responsible for authenticating requests, which they accomplish by implementing an authentication mechanism. Authentication mechanisms define how to encode a credential, such as a password or an assertion from an identity provider (IdP), in a request.
I had the same problem myself. Seems like passport should have an official answer to this. Simplest way it to make a middleware. This middleware would need to be in TWO places. First in the register function so that the username is saved in lowercase. Then in the Login function as shown below for an example. Good luck!
function usernameToLowerCase(req, res, next){
req.body.username = req.body.username.toLowerCase();
next();
}
router.post("/login", usernameToLowerCase, passport.authenticate("local", {
successRedirect: "/",
failureRedirect: "/login"
}), function (req, res) {
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With