Welcome Guest, Not a member yet? Register   Sign In
Help please on encryption
#1

[eluser]softtop[/eluser]
hey,

this is the first time i have mucked around with php, iv got the uploadr script some one made on here working but i wanted the script to use a database i already have.

Got it working out of the database i have but the mysql is encrytped with md5 and this script uses plain text passwords so im trying to convert it into md5, can some one please correct this code for me Smile

Uploader ;

http://net.tutsplus.com/tutorials/php/cr...deigniter/

Orginal:

$query = $this->db->get_where('e107_user', array('user_loginname'=>$username, 'user_password'=>$password));


New one i tryed editing :

$query = $this->db->get_where('e107_user', array('user_loginname'=>$username, ('password'=> md5($password));
echo md5($password);
#2

[eluser]toopay[/eluser]
Thats would be
Code:
$query = $this->db->where('user_loginname', $username)
                  ->where('user_password', md5($password))
                  ->get();
Next time you post code in this forums, use code tags between your code, okay ;-)
Code:
// Remove spaces
[code ]===Your Code Here===[/code ]
#3

[eluser]softtop[/eluser]
hmmm i seem to be getting this error now

A Database Error Occurred
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `user_loginname` = 'test' AND `user_password` = '179ad45c6ce2cb97cf1029e21' at line 2

SELECT * WHERE `user_loginname` = 'test' AND `user_password` = '179ad45c6ce2cb97cf1029e212046e81'

Here is the whole document code
Code:
<?php

class Users extends Model {
    
    function Users()
    {
        // Call the Model constructor
        parent::Model();
    }

    function register($username, $password)
    {
        $new_user = array (
            'user_loginname'=>$username,
            'user_password'=>$password
        );

        $this->db->insert('e107_user', $new_user);

        return true;
    }
    
    function login($username, $password)
    {
    
        $query = $this->db->where('user_loginname', $username)
                          ->where('user_password', md5($password))
                          ->get();
    
    
        if ($query->num_rows()==0) return false;
        else{
            $result = $query->result();
            $user_id = $result[0]->user_id;

            return $user_id;
        }

    }

}
#4

[eluser]toopay[/eluser]
Oops, i didn't include the table name, here you go
Code:
<?php

class Users extends Model {
    
    function Users()
    {
        // Call the Model constructor
        parent::Model();
    }

    function register($username, $password)
    {
        $new_user = array (
            'user_loginname' => $username,
            // You should encrypt this too right?
            'user_password' => md5($password)
        );

        $this->db->insert('e107_user', $new_user);

        return true;
    }
    
    function login($username, $password)
    {
    
        $query = $this->db->where('user_loginname', $username)
                          ->where('user_password', md5($password))
                          ->get('e107_user');
    
        
        if ($query->num_rows()==0) return false;
        else{
            $result = $query->result();
            $user_id = $result[0]->user_id;

            return $user_id;
        }

    }

}
#5

[eluser]softtop[/eluser]
Ahhh dude it worked Big Grin thank you sooooooo much Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB