title: PassportJS Compare Confirm Password Field
body: <p>I am using PassportJS with my ExpressJS app and I am trying to set up a password confirmation field with my user sign up.  My original thought is to make this a view/controller setup rather than involving a model to simplify this process, but I am having an issue with the way I am trying to achieve this logic as my passportJS localStrategy is not checking that the two field values match. Am I approaching this in the right manner?</p>
  
  <p><strong>PassportJS logic (req.user &amp;&amp; password === confirmPassword):</strong></p>
  
  <pre><code>var passport = require('passport');
  var LocalStrategy = require('passport-local').Strategy;
  var models = require('../app/models/db-index');
  var bcrypt   = require('bcrypt-nodejs');
  
      //Sign Up Logic
      passport.use('local-signup', new LocalStrategy({
          passReqToCallback: true,
          usernameField: 'email'
      }, function(req, email, password, done){
          models.User.findOne({
              where: {
                  email: email
              }
          }).then(function(existingUser){
              if (existingUser)
                  return done(null, false, req.flash('error', 'Email already exists.'));
              if (req.user &amp;&amp; password === confirmPassword) {
                  var user = req.user;
                  user.firstName = firstName;
                  user.lastName = lastName;
                  user.email = email;
                  user.password = models.User.generateHash(password);
                  user.save().catch(function(err){
                      throw err;
                  }).then(function(){
                      done(null, user, req.flash('error', 'All fields need to be filled in'));
                  });
              } else {
                  var newUser = models.User.build({
                      firstName: req.body.firstName,
                      lastName: req.body.lastName,
                      email: req.body.email,
                      password: models.User.generateHash(password)
                  });
  
                  newUser.save().then(function(){
                      done(null, newUser);
                  }).catch(function(err){
                      done(null, false, console.log(err));
                  });
              }
          }).catch(function(e){
              done(null, false, req.flash('error', 'All fields need to be filled in'),console.log(e.email + e.message));
          })
      }));
  </code></pre>
  
  <p><strong>Route:</strong></p>
  
  <pre><code>*====   /SIGN-UP    ====*/
  
  
      siteRoutes.route('/sign-up')
  
          .get(function(req, res){
              res.render('pages/site/sign-up.hbs',{
                  error: req.flash('error')
              });
          })
  
          .post(passport.authenticate('local-signup', {
              successRedirect: '/app/sign-up/organization',
              failureRedirect: '/sign-up'
          }));
  </code></pre>
  
  <p><strong>View:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;head&gt;
      {{&gt; site/head}}
  &lt;/head&gt;
  &lt;body&gt;
      {{&gt; site/navigation}}
      &lt;div class="container"&gt;
          &lt;div class="col-md-6 col-md-offset-3"&gt;
              {{#if error}}
                  &lt;div class="alert alert-danger"&gt;{{error}}&lt;/div&gt;
              {{/if}}
              &lt;h1&gt;Sign Up&lt;/h1&gt;
              &lt;form action="/sign-up" method="post"&gt;
                  &lt;input type="text" class="form-control" id="sign-up-fist-name"  name="firstName" value="" placeholder="First Name"&gt;
                  &lt;br /&gt;
                  &lt;input type="text" class="form-control" id="sign-up-username"  name="lastName" value="" placeholder="Last Name"&gt;
                  &lt;br /&gt;
                  &lt;input type="text" class="form-control" id="sign-up-username"  name="email" value="{{user.email}}" placeholder="Email"&gt;
                  &lt;br /&gt;
                  &lt;input type="password" class="form-control" id="sign-up-password"  name="password" value="" placeholder="Password"&gt;
                  &lt;br /&gt;
                  &lt;input type="password" class="form-control" id="sign-up-password"  name="confirmPassword" value="" placeholder="Confirm Password"&gt;
                      &lt;button type="submit"&gt;Submit&lt;/button&gt;
              &lt;/form&gt;
              &lt;a href="/login"&gt;Already have an account? Login here!&lt;/a&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>