title: Passportjs with MySQL in NodeJS
body: <p>Hi everyone i try to connect to a MySQL database to authenticate the user through <code>passport.js</code>, I do not know what's wrong in my source code. When I gave correct or wrong user and password information it results in a redirect failure. Can anyone tell me what's wrong? I am new to this.</p>
  
  <p>Here is my source code:</p>
  
  <pre><code>var flash = require('connect-flash');
  var express = require('express');
  var passport = require('passport');
  var LocalStrategy = require('passport-local').Strategy;
  app.use(flash());
  app.use(passport.initialize());
  app.use(passport.session());
  passport.use(new LocalStrategy(function(username,password,done){
     connection.query("select * from userinfo where UserName='"+username+"'     ",function(err,user){
      if(err)
      {
          return done(err);           
      }
      if(!user)
      {
          return done(null,false,{message: 'Incorrect user name'});           
      }
      if(user.password != password)
      {
         return done(null,false,{message: 'Incorrect password'});
      }
  
      return done(null,user);     
  
     });
  }
  ));
  
  passport.serializeUser(function(user, done) {
    done(null, user);
  });
  
  passport.deserializeUser(function(user, done) {
  done(null, user);
  });
  
  app.post('/validates', passport.authenticate('local',{successRedirect: '/productdisplay', failureRedirect: '/validate', failureFlash: true }));
  </code></pre>
  
  <p>and also the flash message is not working. Please tell me, I almost spent a lot of time in this and I am not get any error. I don't know how to solve this.</p>