title: authentication using node.js and mongodb
body: <p>Guys I am trying to get myself authenticated and for this I am using node.js and mongo DB.But the thing is that after registarion the user is not able to authenticate himself.Here is my snippet</p>
  
  <pre><code>app.post('/login',function(req,res){
      ContactProvider.findAll(function(error, posts) {
          var aut = req.body;
          if (aut.user == posts.user &amp;&amp; aut.pass == posts.pass) {
              req.session.name = {name:aut.user};
              res.redirect('/home');
          } else {
              res.send('Bad user/pass');
          }
      });
  }); 
  </code></pre>
  
  <p>Below is my snippet for registering the user</p>
  
  <pre><code>app.post('/register',function(req, res) {
      var post=req.body;
      if(post.pass!=post.cpass) {
          res.send("Error:Password doesnt match");
      } else {
          ContactProvider.save({
              user: req.param('user'),
              pass: req.param('pass'),
              cpass: req.param('cpass'),
              email: req.param('email')
          }, function(error, docs) {
              res.redirect('/');
          });
      }
  }); 
  </code></pre>
  
  <p>The ContactProvider is the one below where post provider is a different file where all the mongoose things happen</p>
  
  <pre><code>var ContactProvider = require('./PostProvider').ContactProvider;
  var ContactProvider= new ContactProvider(); 
  </code></pre>
  
  <p>This is the finone query in the postprovider file</p>
  
  <pre><code>ContactProvider.prototype.findone = function(name,pass, callback) {
    Post.findOne({name:name},{pass:pass}, function (err, post) {
                    callback(null, post);
  
            });
    };
  </code></pre>