/    Sign up×
Community /Pin to ProfileBookmark

Problem with php and mysql login

Hi, i have little problem, i found simple login system and using to login existing database, but all passowrds hashed i think is sha256, and user can only login with hash, not he’s password.
Here is example

[CODE] $SHA$c325d138e7a5b67d$3d8740300cc0292a513f750b0d872a71b16c9430cc3ff9d8ca8d29c8d081eb04 [/CODE]

maybe somone can help me, and user can login with he’s normal password.

[B]Here is login.php:[/B]

[code=php]<html>
<head>
<title>User Login Form – PHP MySQL Login System</title>
</head>
<body>
<h1>User Login Form – PHP MySQL Login System/h1>
<?php
if (!isset($_POST[‘submit’])){
?>
<!– The HTML login form –>
<form action=”<?=$_SERVER[‘PHP_SELF’]?>” method=”post”>
Username: <input type=”text” name=”username” /><br />
Password: <input type=”password” name=”password” /><br />

<input type=”submit” name=”submit” value=”Login” />
</form>
<?php
} else {
require_once(“db_const.php”);
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
echo “<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>”;
exit();
}

$username = $_POST[‘username’];
$password = $_POST[‘password’];

$sql = “SELECT * from authme WHERE username LIKE ‘{$username}’ AND password LIKE ‘{$password}’ LIMIT 1”;
$result = $mysqli->query($sql);
if (!$result->num_rows == 1) {
echo “<p>Invalid username/password combination</p>”;
} else {
echo “<p>Logged in successfully</p>”;
// do stuffs
}
}
?>
</body>
</html>[/code]

[B]Thank you ?[/B]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmJul 30.2014 — From your text it sounds like your password is hashed prior to storing in the db. Makes sense. Your problem now is that you need to use the same hash on the incoming password and then use THAT value in your query to match to the db value.

PS - I would suggest you do NOT want to query for Like matches. You want EXACT matches (=) only. You don't want to login someone who makes a close guess to a password or user id!
Copy linkTweet thisAlerts:
@ginerjmJul 30.2014 — From your text it sounds like your password is hashed prior to storing in the db. Makes sense. Your problem now is that you need to use the same hash on the incoming password and then use THAT value in your query to match to the db value.

PS - I would suggest you do NOT want to query for Like matches. You want EXACT matches (=) only. You don't want to login someone who makes a close guess to a password or user id!
Copy linkTweet thisAlerts:
@KalobTaulienAug 01.2014 — It looks like your Passwords are hashed (a good thing).

If the problem is users cannot sign into their accounts, and you have their email addresses, simply reset all their passwords and email their temporary password to them or (better solution) upgrade your security and email your existing user base to let them know that your service has new security and requires them to reset their password (create a password reset script).

Passwords should never be decrypted or decryptable, otherwise they are not considered to be "safe".

[HR][/HR]

Kalob
Copy linkTweet thisAlerts:
@KrunalAug 02.2014 — Try This

$hashedPW = $_POST['password'];

$password= hash('sha256', $hashedPW);
Copy linkTweet thisAlerts:
@onlineustaadOct 13.2014 — Hi dude, you can use this simple tutorial to create a very nice and secure login form for your website:

http://www.onlinetuting.com/create-login-script-in-php/
×

Success!

Help @arnas120 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...