public function login()
{
if (parent::login()) {
// Setup our view of the user
$name = new String($this->sharedState->get(SharedStateKeys::LOGIN_NAME));
if ($name instanceof Principal) {
$this->identity = name;
} else {
$name = $name->__toString();
try {
$this->identity = $this->createIdentity($name);
} catch (\Exception $e) {
// log.debug("Failed to create principal", e);
throw new LoginException(sprintf('Failed to create principal: %s', $e->getMessage()));
}
}
$password = new String($this->sharedState->get(SharedStateKeys::LOGIN_PASSWORD));
/* if ($password instanceof char[] ) {
credential = (char[]) password;
} elseif (password != null) {
String tmp = password.toString();
credential = tmp.toCharArray();
} */
return true;
}
$this->loginOk = false;
// array containing the username and password from the user's input
list($name, $password) = $this->getUsernameAndPassword();
if ($name == null && $password == null) {
$this->identity = $this->unauthenticatedIdentity;
// super.log.trace("Authenticating as unauthenticatedIdentity="+identity);
}
if ($this->identity == null) {
try {
$this->identity = $this->createIdentity($name);
} catch (\Exception $e) {
// log.debug("Failed to create principal", e);
throw new LoginException(sprintf('Failed to create principal: %s', $e->getMessage()));
}
// hash the user entered password if password hashing is in use
if ($this->hashAlgorithm != null) {
$password = $this->createPasswordHash($name, $password);
// validate the password supplied by the subclass
$expectedPassword = $this->getUsersPassword();
}
// validate the password
if ($this->validatePassword($password, $expectedPassword) === false) {
// super.log.debug("Bad password for username="+username);
throw new FailedLoginException('Password Incorrect/Password Required');
}
}
// query whether or not password stacking has been activated
if ($this->getUseFirstPass()) {
// add the username and password to the shared state map
$this->sharedState->add(SharedStateKeys::LOGIN_NAME, $name);
$this->sharedState->add(SharedStateKeys::LOGIN_PASSWORD, $this->credential);
}
$this->loginOk = true;
// super.log.trace("User '" + identity + "' authenticated, loginOk="+loginOk);
return true;
}