It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

Two questions about security - hash and session

Moderator: Malcolm

Two questions about security - hash and session

Postby nighthawk on Wed Aug 27, 2008 4:57 pm

I haven't been working with php for a long time, and I forgot many things (not that I was expert before :( ).

Now I'm working on a website for my friend and this is what bothers me:

1)Is it safer to use something like this
[php]function hasher($input){
$output=sha1($input);
$output=substr($output,10,20);
$output=$output.'Chernobile+123';//random text
$output=sha1($output);
$output=md5($output).'Horse+321';
$output=sha1($output);

return $output;
}
[/php]

or just a normal hashing function and only once, like just $output=sha1($input);

2)Here's code that I use for logging on:
[php]$userquery=mysql_query("SELECT username,password FROM
basicuser WHERE username='$username'
AND password='$password'");

if (mysql_num_rows($userquery)!=1) {
echo 'Log in error, bad password or username';
die;
}
$_SESSION['user']=$username;

[/php]

And every other file begins with

[php]
session_start();
if (!isset ($_SESSION['user'])) {
echo 'You must log in';
die;
}
[/php]

Log Out
[php]
session_start();
$old_user=$_SESSION['user'];
unset($_SESSION['user']);
session_destroy();
[/php]

Is this safe - are there any security holes? Thanks in advance.
The Zeitgeist Movement
User avatar
nighthawk
250+ Club
 
Posts: 420
Joined: Sun Jun 11, 2006 1:53 pm
Location: SFRJ

Who is online

Users browsing this forum: No registered users and 0 guests