[PHP]whirlpool hash [+REP]
#1

hello guys
i need help how to hash and read password in this login form and thnx

pawn Код:
<?php

include("config.php"); // including our config.php where is connecting to mysql...
session_start(); //starting session for profile.php (Dunno how to explain better) look little down
error_reporting(0); //without this we will always get some stupid notice that variable isn't defined....

$submit = $_POST['submit']; //variable for submit button, in this variable we save button that player press in <input type='submit' name="submit" value='Login' />....
$username = sanitize($_POST['username']); //variable for username, in this variable we save text that user type in <input type="text" name="username"....
$password = sanitize($_POST['password']); //variable for password, in this variable we save text that user type in <input type="password" name="password"....

if($submit) //if he press submit button
{    
    if($username && $password) //if he type both of username and password not just one of them
    {

        $query = mysql_query("SELECT Username, Password FROM players WHERE username = '$username'"); //selecting user name and password, change it to your field names,  chage users to your table name, $username means username that he type...
        if(mysql_num_rows($query) == 1) //if user exists
        {
            while($row = mysql_fetch_assoc($query)) //loop thought table that we select in mysql_query
            {
                $dbusername = $row['Username']; //setting dbusername as variable from table, change 'username' to your field!
                $dbpassword = $row['Password']; //setting dbpassword as variable from table, change 'password' to your field!
            }
            if($username == $dbusername && $password == $dbpassword) //if username is same as one from table and if password is the same as one from table...
            {
                $_SESSION['username'] = $dbusername; //setting session username to one from table, this is useful if you login, that restart your browser and than you go in url where is your profile.php... Anyway this is useful :D
                echo header('location: profile.php'); //redirecting user to his profile page (profile.php)
            }
            else echo header("Location:login_attempt.php"); //else if user type wrong password he will get this...
        }
        else echo header("Location:login_attempt.php"); //if username doesn't exist in table user will get this
    }
    else echo header("Location:login_attempt.php"); //else if user doesn't type all fields he will get this...
}

?>
<!--
Author: W3layouts
Author URL: [url]http://w3layouts.com[/url]
License: Creative Commons Attribution 3.0 Unported
License URL: [url]http://creativecommons.org/licenses/by/3.0/[/url]
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="css/style.css" rel='stylesheet' type='text/css' />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!--webfonts-->
<link href='http://fonts.******apis.com/css?family=Oxygen:400,300,700|Open+Sans:400,300,600,700' rel='stylesheet' type='text/css'>
<!--//webfonts-->
</head>
 
<body>
    <div class="main">
        <div class="user">
            <img src="images/user.png" alt="">
        </div>
        <div class="login">
            <div class="inset">
                <!-----start-main---->
                <form action='index.php' method='POST'>
                     <div>
                        <span><label>Username</label></span>
                        <span><input type="text" name="username" class="textbox" id="active" value='<?php echo $username?>'/></span>
                     </div>
                     <div>
                        <span><label>Password</label></span>
                        <span><input type="password" class="password" name="password"/></span>
                     </div>
                    <div class="sign">
                        <div class="submit">
                          <input type='submit' name="submit" value='Login'onclick="myFunction()"/>
                        </div>
                    </div>
                    </form>
                </div>
            </div>
        <!-----//end-main---->
        </div>
         <!-----start-copyright---->
                    <div class="copy-right">
                        <p> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
                        <p>SA-MP - UCP BY -<a href="skype:houssam.loukili2">ChichaRito</a> V.0.1 ( Beta )</p>
                    </div>
                <!-----//end-copyright---->
     
</body>
</html>
Reply
#2

plz help
Reply
#3

Use MD5 for that
Reply
#4

No don't use MD5, it's outed dated and not considered a good practice, use:

PHP код:
hash('Whirlpool'$stringtohash); 
So your code would be like this:

PHP код:
            while($row mysql_fetch_assoc($query)) //loop thought table that we select in mysql_query
            
{
                
$dbusername $row['Username']; //setting dbusername as variable from table, change 'username' to your field!
                
$dbpassword hash('whirlpool'$row['Password']); //setting dbpassword as variable from table, change 'password' to your field!
            
}
            if(
$username == $dbusername && hash('whirlpool'$password) == $dbpassword//if username is same as one from table and if password is the same as one from table...
            
{
                
$_SESSION['username'] = $dbusername//setting session username to one from table, this is useful if you login, that restart your browser and than you go in url where is your profile.php... Anyway this is useful :D
                
echo header('location: profile.php'); //redirecting user to his profile page (profile.php)
            

Also remember this isn't a PHP site, and you could have easily found it by searching..

Remember that you will need to update your register side: INSERT INTO.
Reply
#5

Quote:
Originally Posted by vannesenn
Посмотреть сообщение
Use MD5 for that
but my server uses whirlpool hash
plz help
Reply
#6

Quote:
Originally Posted by Isolated
Посмотреть сообщение
No don't use MD5, it's outed dated and not considered a good practice, use:

PHP код:
hash('Whirlpool'$stringtohash); 
where to put this?
here? $password = hash('Whirlpool',$_POST['password']);
Reply
#7

See my edited post.
Reply
#8

Quote:
Originally Posted by Isolated
Посмотреть сообщение
No don't use MD5, it's outed dated and not considered a good practice, use:

PHP код:
hash('Whirlpool'$stringtohash); 
So your code would be like this:

PHP код:
            while($row mysql_fetch_assoc($query)) //loop thought table that we select in mysql_query
            
{
                
$dbusername $row['Username']; //setting dbusername as variable from table, change 'username' to your field!
                
$dbpassword hash('whirlpool'$row['Password']); //setting dbpassword as variable from table, change 'password' to your field!
            
}
            if(
$username == $dbusername && hash('whirlpool'$password) == $dbpassword//if username is same as one from table and if password is the same as one from table...
            
{
                
$_SESSION['username'] = $dbusername//setting session username to one from table, this is useful if you login, that restart your browser and than you go in url where is your profile.php... Anyway this is useful :D
                
echo header('location: profile.php'); //redirecting user to his profile page (profile.php)
            

Also remember this isn't a PHP site, and you could have easily found it by searching..

Remember that you will need to update your register side: INSERT INTO.
i entered the password to login but i get error
"You Have Entred a Wrong Username Or Password !"
Reply
#9

Private message me your full code, this is a Pawn forum so not really supposed to be answering your questions here.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)