Reference

Guide

$user->login()

Logs the user in

$user->login(string $password, \Session|array $session = null): bool

Parameters

Name Type Default Description
$password string
$session Session|array null

Session options or session object to set the user in

Return type

bool

Exceptions

Type Description
PermissionException

If the password is not valid

Example

// simple login form submission example
if($username = get('username') and $password = get('password')) {

  $user = $kirby->user($username);

  if($user and $user->login($password)) {
    // redirect to the homepage
    // or any other page
    go();
  } else {
    echo 'invalid username or password';
  }

}

// put the login form with username and
// password field down here.

Source code

kirby/src/Cms/User.php#L378