Trim username

This commit is contained in:
Wingysam 2018-12-03 17:03:43 -05:00
parent 22b536454b
commit 19b660f024
3 changed files with 4 additions and 3 deletions

View file

@ -18,6 +18,7 @@ const db = new PouchDB(config.dbUrl);
passport.use('local', new LocalStrategy( passport.use('local', new LocalStrategy(
(username, password, done) => { (username, password, done) => {
username = username.trim();
db.get(username) db.get(username)
.then(doc => { .then(doc => {
bcrypt.compare(password, doc.password, (err, correct) => { bcrypt.compare(password, doc.password, (err, correct) => {

View file

@ -19,12 +19,12 @@ module.exports = (db) => {
bcrypt.hash(req.body.newUserPassword, null, null, async (err, newUserPasswordHash) => { bcrypt.hash(req.body.newUserPassword, null, null, async (err, newUserPasswordHash) => {
if (err) throw err; if (err) throw err;
await db.put({ await db.put({
_id: req.body.newUserUsername, _id: req.body.newUserUsername.trim(),
password: newUserPasswordHash, password: newUserPasswordHash,
admin: false, admin: false,
wishlist: [] wishlist: []
}); });
req.flash('success', `Successfully added user ${req.body.newUserUsername}!`); req.flash('success', `Successfully added user ${req.body.newUserUsername.trim()}!`);
res.redirect('/admin-settings'); res.redirect('/admin-settings');
}); });
}); });

View file

@ -22,7 +22,7 @@ module.exports = (db) => {
bcrypt.hash(req.body.adminPassword, null, null, (err, adminPasswordHash) => { bcrypt.hash(req.body.adminPassword, null, null, (err, adminPasswordHash) => {
if (err) throw err; if (err) throw err;
db.put({ db.put({
_id: req.body.adminUsername, _id: req.body.adminUsername.trim(),
password: adminPasswordHash, password: adminPasswordHash,
admin: true, admin: true,
wishlist: [] wishlist: []