bergie / midcom

MVC framework for PHP and the Midgard content repository

This URL has Read+Write access

bergie (author)
Wed Jun 24 21:57:52 -0700 2009
commit  afd3f46b73d85a8d425b845a593a65afd8afb5e3
tree    681bcb7d31b4da4eaecb1c993c3ca2e01fde0dfd
parent  320e0614676db7a65372a5d321d02c570fde2668
midcom / com_rohea_account / passwordhelper.php
100755 83 lines (74 sloc) 2.235 kb
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
<?php
/**
* Class provides simple helpers for passwords
*/
class com_rohea_account_passwordhelper
{
    function __construct()
    {
     
    }
    
    var $validation_error;
    
    /**
* Creates an encrypted password
* DEPRECATED: USE CORE's OWN functionss
* @param string password in plain text
* @return string crypted password
*/
    function crypt_password($password_plaintext)
    {
        // Create an encrypted password
        $salt = chr(rand(64,126)) . chr(rand(64,126));
        $password_crypted = crypt($password_plaintext, $salt);
        return $password_crypted;
    }
    
    /**
* Checks if the password is good enough to be used
* @param string password in plaintext
* @param string retyped password in plaintext
*/
    function check_password_quality($password, $password2)
    {
        if ($password !== $password2)
        {
            return false;
        }
        if (strlen($password) < 5 || strlen($password) > 30)
        {
            return false;
        }
        return true;
    }
    
    function check_input_similarity($password, $password2)
    {
        if ($password !== $password2)
        {
            return false;
        }
        return true;
    }
    
    public function validate()
    {
        if(!isset($_POST['pw']) && !isset($_POST['pw2']))
        {
            return true;
        }
        $password = $_POST['pw'];
        $password2 = $_POST['pw2'];
        
        if(strlen($password) == strlen($password2) && strlen($password) == 0)
        {
            
            return array('bool' => true, 'error' => $this->validation_error);
        }
        if(! com_rohea_account_passwordhelper::check_password_quality($password, $password2))
        {
            $this->validation_error = "bad_quality";
            return array('bool' => false, 'error' => $this->validation_error);
        }
        if(! com_rohea_account_passwordhelper::check_input_similarity($password, $password2))
        {
            $this->validation_error = "similar";
            return array('book' => false, 'error' => $this->validation_error);
        }
        return true;
    }
        
}
?>