aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/auth_plugins/StudipAuthStandard.class.php
blob: c195053cfc99d6bfd46c18ecbc0eac9447bdf9df (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
// +---------------------------------------------------------------------------+
// This file is part of Stud.IP
// StudipAuthStandard.class.php
// Basic Stud.IP authentication, using the Stud.IP database
//
// Copyright (c) 2003 André Noack <noack@data-quest.de>
// Suchi & Berg GmbH <info@data-quest.de>
// +---------------------------------------------------------------------------+
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
// +---------------------------------------------------------------------------+
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// +---------------------------------------------------------------------------+

/**
* Basic Stud.IP authentication, using the Stud.IP database
*
* Basic Stud.IP authentication, using the Stud.IP database
*
* @access   public
* @author   André Noack <noack@data-quest.de>
* @package
*/
class StudipAuthStandard extends StudipAuthAbstract
{

    var $bad_char_regex =  false;

    /**
     * Constructor
     *
     *
     * @access public
     *        
     */
    function __construct()
    {
        parent::__construct();
    }

    /**
    *
    *
    *
    * @access 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;
        } elseif ($user->username != $username) {
            $this->error_msg = _("Bitte achten Sie auf korrekte Gro&szlig;-Kleinschreibung beim Username!");
            return false;
        } elseif (!is_null($user->auth_plugin) && $user->auth_plugin != "standard") {
            $this->error_msg = sprintf(_("Dieser Benutzername wird bereits über %s authentifiziert!"),$user->auth_plugin) ;
            return false;
        } else {
            $pass = $user->password;   // Password is stored as a md5 hash
        }
        $hasher = UserManagement::getPwdHasher();
        $old_style_check = (mb_strlen($pass) == 32 && md5($password) == $pass);
        $migrated_check = $hasher->CheckPassword(md5($password), $pass);
        $check = $hasher->CheckPassword($password, $pass);
        $old_encoding_check = $hasher->CheckPassword(legacy_studip_utf8decode($password), $pass);

        if (($migrated_check || $old_style_check || $old_encoding_check) && !$check) {
            // time to convert the password
            $user->password = $hasher->HashPassword($password);
            $user->store();
        }

        if (!($check || $migrated_check || $old_style_check || $old_encoding_check)) {
            $this->error_msg= _("Das Passwort ist falsch!");
            return false;
        } else {
            return true;
        }
    }

    function isUsedUsername($username)
    {
        return User::findByUsername($username) ? true : false;
    }

}