Location: PHPKode > projects > Homeless Mangement Information System > hmis/include/passwords_class.inc
<?php
//*Client Data System, Copyright (C) 2000, 2001, 2002, 2003 Tedd Kelleher.  This is free software, subject to the 
//*GNU GENERAL PUBLIC LICENSE, Version 2, June 1991 (in file named gpl.txt), which should accompany 
//*any distribution of this file.  Tedd Kelleher can be contacted at hide@address.com

class Passwords {
    var $login_error;
    var $password_error;
    var $vetted_login;
    var $vetted_passwword;

    function check_login_and_password ( $login, $password )
    {
    
        if ( strlen ( $login ) < 8 )
        {
            $this->login_error .= 'Login is too short, must be at least 8 characters long. ';    
        }
        
        if ( strlen ( $login ) > 50 )
        {
            $this->login_error .= 'Login is too long. ';
        }
        
        //Check for illegal characters in login
        if ( ereg ( "[^A-Za-z0-9\)\[:space:]\(\.\?\,\!\#\&\$\@\/\=\:\_\>\<\*\}\{\\]\[+\-]", $login ) )
        {
            $this->login_error .= 'Illegal characters in login. ';
            $this->vetted_login = '';
        }
        
        //Check to see if login already exists
        if ( !$this->login_error )
        {
            $sql_login = "
            SELECT * 
                FROM gate 
                WHERE 
                    gate_login LIKE '".addslashes ( $login )."'";
                    
            $login_result = run_query ( $sql_login, 'Checking for duplicate logins' );
            
            if ( num_rows (  $login_result ) > 0 )  {
                $this->login_error .= 'Login already exists. ';  
            
            } 
        
        }
        
        //Login is OK, so let assign it to a val
        if ( !$this->login_error )  {
            $this->vetted_login = $login;
        
        }
        
        ////PASSWORD CHECK
        
        if ( strlen ( $password ) < 8 )
        {
            $this->password_error .= 'Password is too short, must be at least 8 characters long. ';    
        }
        
        if ( strlen ( $password ) > 50 )
        {
            $this->password_error .= 'Password is too long. ';
        }
        
        //Check for illegal characters in password
        if ( ereg ( "[^A-Za-z0-9\)\[:space:]\)\(\.\?\,\!\#\&\$\@\/\=\:\_\>\<\*\}\{\+\-]", $password ) ) {
            $this->password_error .= 'Illegal characters in login. ';
            $this->vetted_password = '';
        }
        
        //Check for upper case letters
        if ( !ereg ( "[A-Z]", $password )  )
        {
            $this->password_error .= 'Need upper-case letters in password. ';
        }
        
        //Check for lower letters
        if ( !ereg ( "[a-z]", $password )  )
        {
            $this->password_error .= 'Need lower-case letters in password. ';
        }
        
        //Check for numbers
        if ( !ereg ( "[0-9]", $password )  )
        {
            $this->password_error .= 'Need at least one number in password. ';
        }
        
        //Check for symbols
        //if ( !ereg ( "[\)\(\.\?\,\!\#\&\$\@\/\=\:\_\>\<\*\}\{\\]\[\+\-]", $password )  ) {
        if ( !ereg ( "[\)\(\.\?\,\!\#\&\$\@\/\=\:\_\>\<\*\}\{\+\-]", $password )  )
        {
            $this->password_error .= 'Need at least one of the following symbols in password: ) ( . ? , ! # & $ @ / = : _ > < * } { + -. ';
        }
        
        //Check for words assoicated with system in password
        $check_words_array = array ( 'cted', 'safeharbors', 'hmis' );
        foreach ( $check_words_array AS $cur_word )
        {
            if ( strstr ( $password, $cur_word )
                || strstr ( $password, strtoupper ( $cur_word ) )
                || strstr ( $password, ucwords ( $cur_word ) )  )
            {
                $this->password_error .= 'Password cannot contain names of organizations or words associated with the HMIS system. ';    
            }
            
            //Reverse word
            $len = strlen ( $password );
            
            $reversed_password = '';
            for ( $i = $len; $i >= 0; $i-- )
            {
                $reversed_password .= $password[$i];
            }
            
            if ( strstr ( $reversed_password, $cur_word )
                || strstr ( $reversed_password, strtoupper ( $cur_word ) )
                || strstr ( $reversed_password, ucwords ( $cur_word ) ) 
            )
            {
                $this->password_error .= 'Password cannot contain reversed names of organizations or words associated with the HMIS system. ';    
            
            }
        
        }
        
        //Allow no more than two characters in sequence
        for ( $i = 0; $i < $len; $i = $i + 2 )
        {
            $cur_word = $password[$i].$password[$i].$password[$i];
            
            if ( strstr ( $password, $cur_word )
                || strstr ( $password, strtoupper ( $cur_word ) ) )
            {
                $this->password_error .= 'Password cannot contain more than two repeated characters. ';    
            }
        }
        
        //Prevent the use of the username in password
        if ( strstr ( strtoupper ( $password ), strtoupper ( $login ) ) )
            {
                $this->password_error .= 'Password cannot contain your login. ';
        }
        
        
        
       /*
        //Use pspell if installed, but not really needed since a word alone is not a good password as per baove
        $pspell_link = @pspell_new ( 'en' );
        if ( $pspell_link ) {
            echo "yes a pspell<p>";
            if ( pspell_check ( $pspell_link, $password ) ) {
                 $this->password_error .= 'Password cannot be a word. ';
            }

            if ( pspell_check ( $pspell_link, $reversed_password ) ) {
                 $this->password_error .= 'Password cannot be a word spelled backwards. ';
            }

            if ( !$this->password_error )   {
                $this->vetted_password = $password;    

            }
        
        }
        */
        

    
    }


}



?>
Return current item: Homeless Mangement Information System