CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1

    [RESOLVED] from plain txt to md5 vice versa

    I have the following script.....
    Code:
    <? 
    //always start the session before anything else!!!!!! 
    session_start(); 
    
    if(isset($_POST['username']) && $_POST['password']){ 
    
    $username = $_POST['username']; //name of the text field for usernames 
    $password = $_POST['password']; //likewise here just for the password 
    
    
    //connect to the db 
    mysql_connect("localhost", "root", "password") or die(mysql_error()); 
    mysql_select_db("mp3albums") or die(mysql_error()); 
    //run the query to search for the username and password the match 
    $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'"; 
    $result = mysql_query($query) or die("Unable to verify user because : " . mysql_error()); 
    //this is where the actual verification happens 
        if(mysql_num_rows($result) == 1){ 
        //the username and password match 
        //so set true to yes 
        $true=yes; 
        //and then move them to the index page or the page to which they need to go 
        header('Location: index.php?confirm=$true'); 
        }else{ 
        $err = 'Incorrect username / password.' ; 
        } 
        //then just above your login form or where ever you want the error to be displayed you just put in 
        echo "$err"; 
        } 
    
    
    echo "<html>"; 
    echo "<head>"; 
    echo "</head>"; 
    echo "<body>"; 
    echo "<form action=\"\" method=\"POST\">"; 
    echo "<p>username:";  
    echo "<input name=\"username\" size=\"13\" />"; 
    echo "</p>"; 
    echo "<p>password:"; 
    echo "<input type=\"password\" name=\"password\" size=\"13\" />"; 
    echo "</p>"; 
    echo "<input type=\"submit\" name=\"login\" value=\"Login\" />"; 
    echo "</form>"; 
    echo "</body>"; 
    echo "</html>"; 
    ?>
    in my db the pass is in md5 or like this "6d87ee357656066b2981cb3760a9598e"

    how can i make the above read that db so when the user enters the pass in visual it logs him in?
    New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.

    www.ethans-space.com

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: from plain txt to md5 vice versa

    A simple Google search would have shown you the md5() function. It's one of PHP's most basic functions!!!
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3

    Re: from plain txt to md5 vice versa

    jeee wish I thought of that peej...... i mean what the hell. . . Not my first rodeo... I wouldnt have posted had i not been able to figure it out. my question was where to put the md5 check... in the above script
    New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.

    www.ethans-space.com

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: from plain txt to md5 vice versa

    Since the password is the MD5 hash...put it on the password variable.

    I'm sorry. It was not my intention to offend. It's just that this topic is very basic and you didn't mention that you already knew about the md5() function.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5

    Re: [RESOLVED] from plain txt to md5 vice versa

    this is not helping me. Thanks anyway...

    sorry little irritated
    New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.

    www.ethans-space.com

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: [RESOLVED] from plain txt to md5 vice versa

    Am I not being clear?

    PHP Code:
    $query "SELECT * FROM users WHERE username = '$username' AND password = '" md5($password) . "'"
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured