Dear Sir,
I have used md5 encryption in registration page and also used in login for encrypt password and check with sql database but problem is.
When i register a new account it encrypt the password like
naveen123 = adkjfdaf35a6df54das65fa4dsda4f
but when i login with the same password then it automatically adds
two string extra at the end like
naveen123 = adkjfdaf35a6df54das65fa4dsda4f8c
what i do? please suggest
login HTML
<form name="login" method="POST" action="http://localhost/rb2/checkpoint/index.php">
<label for="username" class="control-label fa-label"><i class="fa fa-user fa-medium"></i></label>
<input type="text" name="username" id="username" placeholder="Username"/><br/>
<label for="password" class="control-label fa-label"><i class="fa fa-lock fa-medium"></i></label>
<input type="password" name="password" id="password" placeholder="Password"/>
<input id="checkbox" type="checkbox" >
<h5 style="margin-left:30px;margin-top:-14px;">Remember me</h5>
<br>
<input type="button" id="sub" name="submit" class="btn_ok" value="Log in"/>
<br>
<a href="#" style="float:right;margin-top:10px;">Forgot Password?</a>
<br>
</form>
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$username = $_POST['username'];
$password = md5($_POST['password']);
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql = "select * from users where username = '$username' and password = '$password'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
if($count==1)
{
$_SESSION['user']= $username;
header("Location:http://localhost/rb2/dashboard");
}
else
{
$error = "Incorrect Username or Password";
}
}
else
{
$error = "";
}
?>
Registration Page
<label for="password" class="control-label">Password</label>
<input type="password" class="form-control" id="password" placeholder="">
</div>
<div class="col-md-6">
<label for="password" class="control-label">Confirm Password</label>
<input type="password" class="form-control" id="password_confirm" placeholder="">
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label><input type="checkbox" name="checkit" id="checkit">I agree to the <a href="javascript:;" data-toggle="modal" data-target="#templatemo_modal">Terms of Service</a> and <a href="#">Privacy Policy.</a></label>
</div>
</div>
<p style="color:#F78E21" class="noname">Enter First name</p>
<p style="color:#F78E21" class="noemail">Enter Email Address</p>
<p style="color:#F78E21"class="nosex">Select Gender</p>
<p style="color:#28AAFF;" class="inemail">Enter valid Email Address</p>
<p style="color:#F78E21" class="phoneno">Enter Mobile No.</p>
<p style="color:#F78E21" class="nouser">Enter a Username</p>
<p style="color:#F78E21" class="nopass">Enter Password</p>
<p style="color:#F78E21" class="conpass">Password and Confirm Password Not Matching</p>
<div class="form-group">
<div class="col-md-12">
<input type="submit" id="submit" value="Create account" class="crystal">
</div>
</div>
</div>
<?php
session_start();
$link = mysql_connect('localhost','root','');
include("dbcon.php");
mysql_select_db("rb",$link) or die('couldnt able to connect db');
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$sex = $_POST['sex'];
$username = str_replace(' ','',$_POST['username']);
$password = str_replace(' ','',$_POST['password']);
$password = md5($password);
$sql = "INSERT into users(firstname,lastname,email,username,password,gender,mobile) values('$fname','$lname','$email','$username','$password','$sex','$mobile')";
mysql_query($sql) or die("$query:<br>".mysql_error());
$_SESSION['user']=$username;
mysql_close($link);
?>
javascript
function checklogin(){
var user = $("#username").val();
var pass = $("#password").val();
var data = 'username=' + user + '&password=' + pass;
$.ajax({
type: 'POST',
data: data,
url: 'checkpoint/index.php',
dataType: 'html',
success: function(res){
alert(res);
if(res==1)
{
alert("OK");
}
else if(res==0)
{
alert("NOT OK");
}
}
});
};
createuser jquery
function createuser(){
var fname = $("#first_name").val();
var lname = $("#last_name").val();
var email = $("#email").val();
var mobile = $("#mobile").val();
var username = $("#username").val();
var password = $("#password").val();
var sex = $("input[name=optionsRadios]:checked").val();
var postdata = 'fname=' + fname + '&lname=' + lname + '&email=' + email + '&mobile=' + mobile + '&username=' + username + '&password=' + password + "&sex=" + sex;
$.ajax({
type: 'POST',
url: 'http://localhost/rb2/php/registration.php',
data: postdata,
success: function(){
window.location.href = "http://localhost/rb2/dashboard";
},
error: function(){
alert("Sorry, There is some problem Please Contact Us");
}
});
};
Database
users
username
----------------
varchar(30) and primary key
Password
------------------------------
varchar(30)
there are many fields but prob in password