aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/auth_plugins/StudipAuthStandard.php
blob: 67e7127418194c430fc7fbe188de69820a2d5653 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
 * Basic Stud.IP authentication, using the Stud.IP database
 *
 * @author André Noack <noack@data-quest.de>
 * @license GPL2 or any later version
 */
class StudipAuthStandard extends StudipAuthAbstract
{
    public $show_login = true;

    /**
     * @return bool
     */
    public function isAuthenticated($username, $password)
    {
        $user = User::findByUsername($username);
        if (!$user || !$password || mb_strlen($password) > 72) {
            $this->error_msg= _('Ungültige Benutzername/Passwort-Kombination!') ;
            return false;
        }

        if ($user->username !== $username) {
            $this->error_msg = _('Bitte achten Sie auf korrekte Groß-Kleinschreibung beim Username!');
            return false;
        }

        if (isset($user->auth_plugin) && $user->auth_plugin !== 'standard') {
            $this->error_msg = sprintf(_('Dieser Benutzername wird bereits über %s authentifiziert!'), $user->auth_plugin) ;
            return false;
        }

        if (!password_verify($password, $user->password)) {
            $this->error_msg= _('Das Passwort ist falsch!');
            return false;
        }

        if (password_needs_rehash($user->password, PASSWORD_DEFAULT)) {
            $user->password = password_hash($password, PASSWORD_DEFAULT);
            $user->store();
        }

        return true;
    }

    /**
     * @return bool
     */
    public function isUsedUsername($username)
    {
        return (bool) User::findByUsername($username);
    }
}