encrypted register and login passwords gone wrong

I have a sign up script:

function NewUser() 
        $fullname = $_POST['name']; 
        $userName = $_POST['user']; 
        $email = $_POST['email']; 
        $password = $_POST['pass'];
        $confirm_password = $_POST['cpass'];
        $salt = 'a salt(not in my real script)';
        $password = crypt($password, $salt);
        $query = "INSERT INTO WebsiteUsers (fullname,userName,email,pass) VALUES ('$fullname','$userName','$email','$password')"; 
        $data = mysql_query ($query)or die(mysql_error()); 

Which works perfectly, it stores everything inclusive the encrypted password. I also have a check login code:

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword 

// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT pass FROM $tbl_name WHERE userName='$myusername' ";
$result = mysql_query($sql); 

if (crypt($user_input, $password) == $password){

// Register $myusername, $mypassword and redirect to file "login_success.php"
else {
echo "Wrong Username or Password";

There is something going wrong in this code that is blocking my login_success.php it will say that is the wrong username or password, I know it is my password that is going wrong with the encryption. Can someone help me debugging this code so it will see the encrypted password in the right way. Because I am testing the websites login but it doesn't work because(what I think) it can't see the encrypted password right.(sorry for my bad english)


A better approach to creating a site with an authentication system is to make use of a development framework that already has one built in.

A good example is Laravel which has a really robust authentication platform that you can use right out of the box.

Need Your Help

Python Request Select() method - Selecting 'pre' Element

python beautifulsoup python-requests

Using Requests and BeautifulSoup to scrape a webpage. Can't seem to get the select() method to work in order to grab the text seen in HTML below.

Javadoc for ORMlite attached, but not found by Eclipse

android eclipse javadoc ormlite

I am using ORMlite 4.41 for Android in Eclipse. Can't seem to get the javadoc to work in Eclipse. I am using the following to ORMlite jars: