title: getting bad request while using passport in login form
body: <p>I am trying to create a user login [.ejs file] form using passport local session in nodejs. My problem is that I keep on getting bad request when I hit on the submit button,can anyone please check my code and help me out</p>
  
  <p>Here is my nodejs code:</p>
  
  <p>required: </p>
  
  <pre><code>var express = require('express');   
  var bodyParser = require('body-parser');
  var passport = require('passport');
  var LocalStrategy = require('passport-local').Strategy;
  var cookieParser = require('cookie-parser')
  var expressSession = require('express-session');
  var mongodb = require('mongodb');
  var mongoose = require('mongoose');
  var app = express();
  var MongoClient = mongodb.MongoClient;
  app.use(expressSession({
      secret: 'secret'
  }));
  app.use(passport.initialize());
  app.use(passport.session());
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({
      extended: false
  }));
  app.set('view engine', 'ejs');
  </code></pre>
  
  <p>passport:</p>
  
  <pre><code>var user = mongoose.model('val', Schema);
  passport.use(new LocalStrategy({
          passReqToCallback: true
      },
      function (firstName, password12, done) {
          console.log("entered Function");
          user.findOne({
                  firstName: firstName
              },
              function (err, firstName) {
                  if (err) {
                      return done(err);
                  }
                  if (!firstName) {
                      console.log('User Not Found  ' + firstName);
                  }
                  if (!isValidPassword(firstName, password12)) {
                      console.log('Invalid Password');
                  } else {
                      console.log('correct');
                      return done(null, firstName);
                  }
              }
          );
      }));
  </code></pre>
  
  <p>login page:</p>
  
  <pre><code>app.get('/login', function (req, res) {
      res.render('login');
  });
  app.post('/login', passport.authenticate('local'), function (req, res){
      var userInfo = req.body;
  });
  </code></pre>