title: Nodejs - Passport authenticate always return failure redirect
body: <p>I'm making a form login by passportJs and it always return failureRedirect. I have search in stack overflow for this issue, but still not have the correct answer. Here is my code:</p>
  
  <ul>
  <li><p>Form making form jade:</p>
  
  <pre><code>form(method='post', action='/users/login', enctype='multipart/form-data')
   .form-group
     label Username
     input.form-control(name='username', type='text'     placeholder='Enter Username')
  .form-group
    label Password
    input.form-control(name='password', type='password' placeholder='Enter password')
  input.btn.btn-default(name='submit', type='submit', value='Login')
  </code></pre></li>
  </ul>
  
  <p>Router Hanlde is using express framework form Nodejs and passport middleware:</p>
  
  <pre><code>passport.serializeUser(function(user, done) {
   done(null, user.id);
  });
  
  passport.deserializeUser(function(id, done) {
  User.getUserById(id, function(err, user) {
      done(err, user);
  });
  });
  
  passport.use(new LocalStrategy({
      usernameField: 'username',
      passwordField: 'password'
  },
  function(username, password, done) {
      User.getUserByUsername(username, function(err, user) {
          if (err) throw err;
          if (!user) {
              console.log('Unknown User');
              return done(null, false, {
                  message: 'Unknown User'
              });
          }
  
          User.comparePassword(password, user.password, function(err, isMatch) {
              if (err) throw err;
              if (isMatch) {
                  return done(null, user);
              } else {
                  console.log('Invalid Password');
                  return done(null, false, {
                      message: 'Invalid Password'
                  });
              }
           });
        });
     }
  ));
  
    router.post('/login', passport.authenticate('local', {
      failureRedirect: '/users/login',
      failureFlash: 'Invalid username or password'
  }), function(req, res) {
  console.log('Authentication Successful');
  req.flash('success', 'You are logged in ');
  res.redirect('/');
   });
  </code></pre>