Finds a user by `username` and `password`

`cb` is passed with the matching user or exceptions.AuthenticationFailed

@param {String} username
@param {String} password
@param {Function} cb
506214
function findByCredentials(username, password, cb) {
  crypto.encode(password, function(err, encoded) {
    if(err) { return cb(err); }

    db.getClient(function(err, client, done) {
      client.query(SELECT_CREDENTIALS, [username, encoded], function(err, r) {
        var result = r && r.rows[0];
        if(!err && !result) { err = new exceptions.AuthenticationFailed(); }
        if(err) {
          cb(err);
          done(err);
        } else {
          cb(null, result);
          done();
        }
      });
    });
  });
}
882789
public function Authenticate($username, $password)
    {
        // Start authentication
        fputs($this->smtp_conn, "AUTH LOGIN" . $this->CRLF);

        $rply = $this->get_lines();
        $code = substr($rply, 0, 3);

        if ($code != 334) {
            $this->error =
            array("error" => "AUTH not accepted from server",
                "smtp_code"   => $code,
                "smtp_msg"    => substr($rply, 4));
            if ($this->do_debug >= 1) {
                echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
            }
            return false;
        }

        // Send encoded username
        fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);

        $rply = $this->get_lines();
        $code = substr($rply, 0, 3);

        if ($code != 334) {
            $this->error =
            array("error" => "Username not accepted from server",
                "smtp_code"   => $code,
                "smtp_msg"    => substr($rply, 4));
            if ($this->do_debug >= 1) {
                echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
            }
            return false;
        }

        // Send encoded password
        fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);

        $rply = $this->get_lines();
        $code = substr($rply, 0, 3);

        if ($code != 235) {
            $this->error =
            array("error" => "Password not accepted from server",
                "smtp_code"   => $code,
                "smtp_msg"    => substr($rply, 4));
            if ($this->do_debug >= 1) {
                echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
            }
            return false;
        }

        return true;
    }
145211
def authenticate_credentials(self, userid, password):
        
        credentials = {
            get_user_model().USERNAME_FIELD: userid,
            'password': password
        }
        user = authenticate(**credentials)

        if user is None:
            raise exceptions.AuthenticationFailed(_('Invalid username/password.'))

        if not user.is_active:
            raise exceptions.AuthenticationFailed(_('User inactive or deleted.'))

        return (user, None)
344602
function (user, req, cb) {
  CoreController.getPluginViewDefaultTemplate({
    viewname: 'email/user/forgot_password_link',
    themefileext: appSettings.templatefileextension,
  },
		function (err, templatepath) {
  if (err) {
    cb(err);
  }			else {
				// console.log('emailForgotPasswordLink templatepath', templatepath);
    if (templatepath === 'email/user/forgot_password_link') {
      templatepath = path.resolve(process.cwd(), 'node_modules/periodicjs.ext.login/views', templatepath + '.' + appSettings.templatefileextension);
    }
				// console.log('user for forgot password', user);
    var coreMailerOptions = {
      appenvironment: appenvironment,
      to: user.email,
      from: appSettings.fromemail || appSettings.adminnotificationemail,
      replyTo: appSettings.fromemail || appSettings.adminnotificationemail,
      subject: loginExtSettings.settings.forgotPasswordEmailSubject || appSettings.name + ' - Reset your password',
      emailtemplatefilepath: templatepath,
      emailtemplatedata: {
        user: user,
        appname: appSettings.name,
        hostname: req.headers.host,
        filename: templatepath,
        adminPostRoute: req.adminPostRoute,
      },
    };
    if (loginExtSettings.settings.adminbccemail || appSettings.adminbccemail) {
      coreMailerOptions.bcc = loginExtSettings.settings.adminbccemail || appSettings.adminbccemail;
    }
    CoreMailer.sendEmail(coreMailerOptions, cb);
  }
}
	);
	// cb(null, options);
}
850900
function hash_verify (password, _hash) {
  let hash = _hash.split('|')
  switch (hash[1]) {
    case 'bcrypt':
      return bcrypt_compare(password, hash[0])
    default:
      return Promise.resolve(password === hash[0])
  }
}
188330
def check_basic_auth(self, username, password):
        
        valid = self.users.check_password(
            username, password
        )
        if not valid:
            log.warning('Invalid login from %s', username)
            valid = False
        return (
            valid,
            username
        )
1115577
def with_username(username, password):
    
    user = models.AuthUser.get_by_username(username)
    return _user(user) if user and user.password_matched(password) else None
63889
async function connectUser(form) {
  if (!form.login.value || !form.password.value) {
    document.getElementById('login-errors').innerHTML += `<p>Login and password are required</p>`;
    return;
  }

  await client.setCredentials({ login: form.login.value, password: form.password.value });
  client
    .connect()
    .then(() => {
      displayMessage('Login success', 'Welcome to wonderful service', 'is-success');
      goTo('home');
    })
    .catch((e) => {
      displayMessage(
        'Login failed',
        'Your account is not validated, have you clicked on the link in the email ?',
        'is-warning'
      );
    });
}
733292
def get_user_and_check_auth(self, username, password):
        
        constraint = sql.or_(
            models.USERS.c.name == username,
            models.USERS.c.email == username
        )

        user = self.identity_from_db(models.USERS, constraint)
        if user is None:
            raise dci_exc.DCIException('User %s does not exists.' % username,
                                       status_code=401)

        return user, auth.check_passwords_equal(password, user.password)
405857
function(token, cb){
      // deserialize the token iss
      var _iss = token.iss.split('|');

      waterlock.User.findOne(_iss[0]).exec(function(err, user){
        if(err){
          waterlock.logger.debug(err);
        }

        cb(err, user);
      });
    }
613485
function (registrationRequest, cb) {
            if (registrationRequest.$.password) {
                var ret = {
                    providerUserId: registrationRequest.get(this.$.usernameField),
                    authenticationData: this.createAuthenticationData(registrationRequest.$.password)
                };
                cb(null, ret);
            } else {
                cb("No password set");
            }
        }
214015
function destroyUser(name, pass, cb) {
  loginUser(name, pass, function(err, user) {
    if(err) return cb(err)
    nano().use(user_dbname).destroy(user._id, user._rev, function(err, doc) {
      if(err) return cb(err)
      user._id = doc.id
      user._rev = doc.rev
      destroyDatabase(name, function(err) {
        if(err) return cb(err)
        cb(null, user)
      })
    })
  })
  // var db = nano().use(user_dbname)
  // db.head(user_namespace+':'+name, function(err, b, h) {
    // if(err) return cb(err)
    // db.destroy(user_namespace+':'+name, JSON.parse(h.etag), function(err, doc) {
      // if(err) return cb(err)
      // destroyDatabase(name, function(err) {
        // if(err) return cb(err)
        // cb(null, doc)
      // })
    // })
  // })
}
770631
function readUser (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, organizationId } = params
      let user

      const tasks = []

      tasks.push((next) => {
        Joi.validate({ id, organizationId }, validationRules.readUser, (err) => {
          if (err) return next(Boom.badRequest(err))
          next()
        })
      })

      tasks.push((next) => {
        const sqlQuery = SQL`
          SELECT id, name, org_id, metadata
          FROM users
          WHERE id = ${id}
          AND org_id = ${organizationId}
        `
        db.query(sqlQuery, (err, result) => {
          if (err) return next(Boom.badImplementation(err))
          if (result.rowCount === 0) return next(Boom.notFound(`User ${id} not found`))

          user = mapping.user(result.rows[0])
          next()
        })
      })

      tasks.push((next) => {
        const sqlQuery = SQL`
          SELECT teams.id, teams.name
          FROM team_members mem, teams
          WHERE mem.user_id = ${id} AND mem.team_id = teams.id
          ORDER BY UPPER(teams.name)
        `
        db.query(sqlQuery, (err, result) => {
          if (err) return next(Boom.badImplementation(err))

          user.teams = result.rows.map(mapping.team.simple)
          next()
        })
      })

      tasks.push((next) => {
        const sqlQuery = SQL`
          SELECT pol.id, pol.name, pol.version, user_pol.variables, user_pol.policy_instance
          FROM user_policies user_pol, policies pol
          WHERE user_pol.user_id = ${id} AND user_pol.policy_id = pol.id
          ORDER BY UPPER(pol.name)
        `
        db.query(sqlQuery, (err, result) => {
          if (err) return next(Boom.badImplementation(err))

          user.policies = result.rows.map(mapping.policy.simple)
          next()
        })
      })

      async.series(tasks, (err) => {
        if (err) return cb(err)

        return cb(null, user)
      })

      return promise
    }
1210749
def get_user_by_password(self, username, password):
        
        try:
            user = self.get(username=username)
        except User.DoesNotExist:
            return None
        
        if bcrypt.hashpw(password, user.pass_hash) == user.pass_hash:
            return user
        else:
            return None
113518
public void signin(String username, String password) {
		logger.debug("signin:" + username);

		Authentication request = new UsernamePasswordAuthenticationToken(username, password, null);
		SecurityContextHolder.getContext().setAuthentication(request);
	}
1092681
function userFound(err, user) {

		if (err) {
			// ensure your using username instead of email
			waterlock.logger.debug(err);

			console.log(err);
			return waterlock.cycle.loginFailure(req, res, null, { error: 'trouble creating model' });
		}

		waterlock.cycle.loginSuccess(req, res, user);
	}
702207
def login(user, password)
      data = request('authenticateUser',
                     { username: user, password: password },
                     true)
      @user = User.new(self, data)
      fail InvalidAuthentication, 'Wrong username or password!' if @user.id == 0

      @user
    end