Security Software review and downloads
  • Home
  • Spyware & Spyware Remover
  • Registry & Registry Cleaner
  • Firewall
  • Hacked
  • Uninstall & Uninstaller
  • Antivirus

PHP and MySQL login routine security question?

May 18th, 2008 · 4 Comments

I found this account login code online:

<?php
require_once('connect.php');
$email = mysql_escape_string(trim(stripslashes($_…

if (!empty($email)) {
$query = "SELECT username, password FROM members WHERE email = '$email'";
$result = mysql_query($query);
while ($row = mysql_fetch_object($result)) {
$username = $row->username;
$password = $row->password;
}
echo "Your username is $username";
echo "Your password is $password";
}
else {
echo "Please enter your email address!";
}

?>

My question is, isn't this very unsafe since if a malicious user does a little digging and finds a user's email address, they can pretty much get their password or am I incorrect? I have a mysql db and and trying to develop a secure php front end with user login. I haven't found any that use hashing algorythms.

Related posts:

  • I'm getting the following error with PHP code pasted below. Please take a look and tell me whats wrong!?
  • The error I am getting is: Catchable fatal error: Object of class mysqli_result could...
  • Php MySQL Database Password problem???!!!?
  • I've made in MySql a Database (members) and 1 table (users) and 2 Fields in it: 1....
  • How do i finish my javascript password protection?
  • I'm having a little problem setting up the security on my site. This is the code that I...
  • Ebay username AND/OR password not working?
  • I'm an Ebay regular and I usually buy 3-5 things every month from Ebay...well a few...
  • How come I get an error using double quotes in PHP?
  • I am a newbie, and am readin MySQL and PHP For Dummies 3rd edition. All the programs have...
  • Whats wrong with this PHP line?: if($_POST[username] == $username && $_POST[password] == $password)?
  • The whole code is this: if(isset($_POST['submit'])) { if($_POST[username]...
  • Creating a URL that contains user name and password?
  • If a web site has a login page where you have to type in a username and password,...
  • I dont reember my myspace password or my email password which is my myspace username. WHAT DO I DO I NEED HELP
  • I recantly changed my myspace password and i cant remember it. My myspace user name is...
  • PHP error message?? Cant get rid of it!?
  • Why do i have this problem im trying to get a dynamic table and was done in dreamweaver...
  • Having Trouble With Recovering My forgotten Adminstrator password on Vista help!!!!!!!!!!!!!!?
  • i followed this 1)Go to Run - Type CMD - Press Enter 2) type net user...

    Tags: Security


    4 responses so far ↓

    • 1 michael p // May 18, 2008

      Obviously it is, it is just an example. there is a lot more to doing this. Like maintaining the session with a cookie indicating the user is logged in etc… Also, you would have to do this over https because otherwise passwords would be sent in clear text. The database validation is not the hard part, it is session management.

      If you want to hash the pass, make it md5 or SHA1. both are built into php. But if you want to make it secure, you need some more php knowledge that I cannot provide in this space

    • 2 Colanth // May 18, 2008

      Not only don't you *EVER* give out a password, you *never* store an unencrypted password. Databases can be broken into.

      Encrypt the password when the account is started (use MD5 - php makes that trivial) and store the ENCRYPTED password. Then, when the user logs in, encrypt the password and compare the ENCRYPTED password to the one stored.

      MD5 can't be decoded - it can be collided, but it's not worth the effort unless it's the password to Fort Knox, or something equally valuable. (You can keep trying passwords untill the MD5 hash of the password you try is the same as the one in the database. At the rate of 1 per second, it could take centuries. And, as I said, it's trivial to MD5-hash a password in php. MD5 is an internal function.)

    • 3 two pi // May 18, 2008

      You're correct that this script is horribly non-secure, but I don't believe it's a login script at all. Instead, it's a script for returning a password for a person who has forgotten it.

      It's still a really bad idea, as you can see that there is no other feature in place to ensure the user is actually the user. That's why most such scripts also include some sort of personal question (mother's maiden name or the like,) which is also stored in the database. You can then check to see if the password and answer relate to the same record before sending the account info back.

      Hashing is one easy way to improve security. Use the md5() or sha1() function to produce a scrambled version of the password when you first receive it from the user. Store this hashed version, so you don't have the password stored in plain text anywhere.

      When the user tries to authenticate, hash the input password with the same function used to store it, and compare the hashed input with the stored hash value.

      Hashing is a pretty good security measure for ordinary site passwords, but it is not strong enough for serious work. Look into more sophisticated techniques like public key encryption if you are working with really sensitive data

      Note that the password is still transmitted in the clear, so a network sniffer could get ahold of it. For that, you'll need to run ssl. It isn't difficult to set up, but you may need cooperation from your server administrator.

      Good luck!

    • 4 Jewish Boy // May 18, 2008

      Yes it is unsafe.
      What it should do is email the password to you.

    Leave a Comment

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word

    Tags: Email Spam Uninstall spyware Security Software Trend Micro Registry Cleaner Pc Tools Norton Nod32 Kaspersky Internet Security Hacked Firewall Computer Security Avg Avast Antivirus Ad Aware Monitoring Software Encryption Backup


    A Slow System?
    Harassed by DLL errors?
    Plagued by constant Blue Screens?
    Receiving error messages and don't know why?

     
    • Most popular Software downloads

      • Pctools
      • kaspersky
    About | Contact Us | Old Sitemap Security Software review and download . All rights reserved PoweredBy Yahoo!API.