<?php
$username = '$_post["username"]';
$password = '$post["password"]';
if ($username&&$password)
{
$connect = mysql_connect("localhost", "josiah", "nastassja") or die ("could not connect");
mysql_select_db ("userlogin") or die ("could not find database");
}
else
die ("wrong username and password");
?>
17 Replies - 2679 Views - Last Post: 23 January 2011 - 12:52 PM
#1
my error message is not showing up when invalid username of password i
Posted 21 January 2011 - 05:58 PM
Replies To: my error message is not showing up when invalid username of password i
#2
Re: my error message is not showing up when invalid username of password i
Posted 21 January 2011 - 06:31 PM
Second, NEVER trust user input, unless you want to be hacked. Read about SQL Injection.
Third, you probably want to check if the variables are set before assigning them.
if (!isset($_POST['username']) || !isset($_POST['password']))
{
die("No username and/or password provided");
}
$connect = mysql_connect("localhost", "josiah", "nastassja") or die ("could not connect");
mysql_select_db ("userlogin") or die ("could not find database");
$username = mysql_real_escape_string($_POST['username');
$password = mysql_real_escape_string($_POST['password');
Also, you should never store your passwords in the database as the user enters them. You should salt and hash them. See this post for a class which will do this for you.
#3
Re: my error message is not showing up when invalid username of password i
Posted 21 January 2011 - 07:40 PM
#4
Re: my error message is not showing up when invalid username of password i
Posted 21 January 2011 - 08:06 PM
#5
Re: my error message is not showing up when invalid username of password i
Posted 22 January 2011 - 01:03 AM
<?php
$username = mysql_real_escape_string($_POST['username']);
$hash1 = sha1($username);
$password = mysql_real_escape_string($_POST['password']);
$hash2 = sha1($password);
if (!isset($_POST['username']) || !isset($_POST['password']))
{
die("missing username and/or password");
}
$connect = mysql_connect("localhost", "****", "****") or die ("could not connect");
mysql_select_db ("userlogin") or die ("could not find database");
?>
i know my username and password are being hashed now at least and sorry for all the posts i just want to get as much done in the next few weeks as i can since ill be a lot busier after that
This post has been edited by Dormilich: 22 January 2011 - 01:20 AM
#6
Re: my error message is not showing up when invalid username of password i
Posted 22 January 2011 - 01:21 AM
#7
Re: my error message is not showing up when invalid username of password i
Posted 22 January 2011 - 02:25 AM
#8
Re: my error message is not showing up when invalid username of password i
Posted 22 January 2011 - 02:49 AM
#9
Re: my error message is not showing up when invalid username of password i
Posted 22 January 2011 - 05:00 AM
There's a REASON that I don't call mysql_real_escape_string until AFTER I connect to the DB...you MUST have a connection to the database to use this function.
Please spend a little bit of time reading this tutorial, and THINKING about what you're doing.
#10
Re: my error message is not showing up when invalid username of password i
Posted 22 January 2011 - 02:19 PM
JackOfAllTrades, on 22 January 2011 - 05:00 AM, said:
There's a REASON that I don't call mysql_real_escape_string until AFTER I connect to the DB...you MUST have a connection to the database to use this function.
Please spend a little bit of time reading this tutorial, and THINKING about what you're doing.
haha thank you for that insightful tutorial
<?php
session_start();
if (!isset($_POST['username']) || !isset($_POST['password']))
{
die("missing username and/or password");
}
else{
$connect = mysql_connect("localhost", "***", "***") or die ("could not connect");
mysql_select_db ("userlogin") or die ("could not find database");
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$hash2 = sha1($password);
$query = mysql_query("SELECT * FROM users WHERE username='$username'");
$numrows = mysql_num_rows($query);
if ($numrows!=0){
while ($row = mysql_fetch_assoc($query)){
$dbuser = $row['username'];
$dbpass = $row['password'];
}
if ($username==$dbuser&&$hash2==$dbpass){
echo "succesfully logged in!<br>";
echo "<a href='http://yourlife.dyndns.org/form.php'> click</a> here to submitt post " ;
$_SESSION['username']=$username;
}
else
die("wrong password");
}
else
die("username does not exist!");
}
echo $_SESSION;
?>
This post has been edited by josiahmahar: 22 January 2011 - 02:25 PM
#11
Re: my error message is not showing up when invalid username of password i
Posted 22 January 2011 - 04:24 PM
echo "<pre>" . print_r($_SESSION, true) . "</pre>";
print_r() displays all contents of an array. The second argument being set to true tells it to return the result instead of outputting it. The <pre> tags tell it that the contents of those tags is pre-formatted and should display line breaks and such as they appear. This is to ensure readability.
This post has been edited by Valek: 22 January 2011 - 04:25 PM
#12
Re: my error message is not showing up when invalid username of password i
Posted 22 January 2011 - 05:29 PM
<?php
session_start();
$time = date("H:i");
echo "welcome", "<pre>" . print_r($_SESSION, true) . "</pre>", "it is $time" ;
?>
i want it so it would show "welcome josiahmahar it is 00:37"
instead of
"welcome Array
(
[username] => josiahmahar
)
it is 00:37"
and do you know why my current time is 6 hours ahead??
This post has been edited by josiahmahar: 22 January 2011 - 05:40 PM
#13
Re: my error message is not showing up when invalid username of password i
Posted 22 January 2011 - 05:38 PM
echo $_SESSION['username']
That'll echo just the username you set earlier in the script.
Also, where is the server it's running on located? If it's on your local PC, you should use some of PHP's time functions to ensure it's using the right timezone. Check out DateTime, specifically DateTime::setTimezone()
This post has been edited by Valek: 22 January 2011 - 05:39 PM
#14
Re: my error message is not showing up when invalid username of password i
Posted 23 January 2011 - 02:22 AM
#15
Re: my error message is not showing up when invalid username of password i
Posted 23 January 2011 - 03:03 AM
The same goes for MySQL, in the case of SELECT queries to ensure the name is not already taken.
This post has been edited by Valek: 23 January 2011 - 04:16 AM
|
|

New Topic/Question
Reply



MultiQuote




|