Q:

not matching password parameter in sails controller

i am newbie in sails and i was making a simple login functionality in which the controller named find is going to db and checking if the user name password is valid or not, but the problem i am facing is it's checking for the user name and i think not for the password because in the param i am passing the correct password, i am passing param through using link simply, the link through which i am passing param is
http://localhost:1337/find/index?name=ahsan&pass=pakistan

and the code in my find controller is
var Sequelize = require('sequelize');
 var sequelize  = require('../../config/config_db').dbase;

    var user = sequelize.define('Data',{
      username: Sequelize.STRING,
      birthday: Sequelize.STRING
    })

sequelize.sync();

module.exports = {

  index: function (req, res) {        

  var n = req.param('name');
  var p = req.param('pass');

  user.find({ where: { username : n, password : p }    })
  .complete(function(err, name, pass)
  {
    if (!!err) 
      {
        return res.json('error while connecting db')
      }
    else if (!name) 
      {
        return res.json('no user with this name')
      }
    else if (!pass)
    {
      return res.json('no user with this password')
    }
    else
    {
      return res.json('user is valid')
    };

})

    // Send a JSON response
    // return res.json({
    //   hello: 'world'

  },

  _config: {}

};

and the query executing in console is
SELECT * FROM `Data` WHERE `Data`.`username`='ahsan' AND `Data`.`password`='pakistan' LIMIT1;

Tthe password pakistan exist in my db and the out it's showing me is
"no user with this password"

please let me know if i am mistaking.

A:

You're misusing the .complete() callback in Sequelize.  It should have two parameters: err and the retrieved item (in this case a user).  Try:
user.find({ where: { username : n, password : p }    })
  .complete(function(err, user)
  {
    if (!!err) 
      {
        return res.json('error while connecting db')
      }
    else if (!user.name) 
      {
        return res.json('no user with this name')
      }
    else if (!user.pass)
    {
      return res.json('no user with this password')
    }
    else
    {
      return res.json('user is valid')
    };       
});

