Welcome visitor
* Login
* Register
It is currently July 23rd, 2019, 2:44 am
All times are UTC [ DST ]
* Search
View unanswered posts - View active topics

FORUMS » Server Side » PHP



Post new topic Reply to topic  [ 3 posts ] 
Author Message
  Secure a Password
PostPosted: February 4th, 2009, 11:16 pm 
User avatar

Posts: 137
Hmm, I'm not sure if my question belongs to this category, but here it goes...
I'm developing a little website for my friends and a few more... Anyway, the case is that I want to add some privacy to it, so basically that's my question, how can I secure some information, like using a password?


Top
 Profile  
 
  Re: Secure a Password
PostPosted: February 5th, 2009, 12:41 am 
User avatar

Posts: 44
Can you be a little more specific Rokstar? :D Cos your question is a little confusing... But yes, you can add privacy to your website by using a password. Now, if you have a little site that nobody knows i dont think that you need a password. Or if you want to use the password to control the access that each user is allowed to have to the information, etc.. you are then talking about a more complex system that involves also a database. Now kissing your question, this is the easiest way to compare a password entered by the user to a predertermined 'password', and I'm supposing that all the users have the same password. Of curse you are going to use the POST method cos sending a passcode through the URL doesn't sound too secure.
extract($_POST);
if ($password =="THEpassword"){       //$password would contain the value entered by the user
}
else {
}


Top
 Profile  
 
  Re: Secure a Password
PostPosted: February 5th, 2009, 1:07 am 

Posts: 55
Yes Rockstar, Neo got his point, so now let me go a little deep to talk about the database thing. On that case you might like to have usernames and passwords as well, so include fields for that on your database. For this example let us call them user_field and pass_field. Now, imagine that through an htm form you got the username on a var called $user and the password on a var called $passcode, both of them were sent via POST to your PHP file. (Please let me know if you need further help with the database or the html form).

Now this would be the PHP code to get the info provided by the user, then connect to the database and finally validate both, username and passcode.
extract($_POST);

mysql_connect('host' , 'user' , 'password');
mysql_select_db('database');

$dbTable=mysql_query("SELECT * FROM table WHERE user_field='$user' AND pass_field='$passcode'");
$resultantRow=mysql_fetch_array($dbTable);

 
if (mysql_num_rows($consultantArray) == 0) { //this line is to validate if the results are 0, failed
}
else { //if there was any then it will go down to this part, it went through
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

FORUMS » Server Side » PHP


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron