Jump to content

How to add Password Security?


booxvid

Recommended Posts

I already had this snippet code in adding users

 

	if(isset($_POST['add_user'])){
	$passw = trim(htmlentities($_POST['password']));

	$encrypted = enc_salt($passw);

	$con = "true";
		$sql = "SELECT * FROM users WHERE username='".$_POST['user_name']."'";
		$result = $database->query($sql);
		$row = $database->fetch_array($result);

		if($row!=""){
			$con="false";
		}

	if($con!="false"){	
	 $sql  = "INSERT INTO photo_gallery.users (username, password, first_name, last_name)";
	$sql .= " VALUES ('".trim(htmlentities($_POST['user_name']))."','".$encrypted."', '".trim(htmlentities($_POST['first_name']))."', '".trim(htmlentities($_POST['last_name']))."')";

	$result_set = $database->query($sql);

	echo '<script type="text/javascript">alert("Account Created!");</script>';}
	else{
		echo '<script type="text/javascript">alert("This username already exist!");</script>';
	}
}

 

where my function enc_salt is:

function enc_salt($string){
//encrypting
$pass_word = sha1($string);
$salt = md5("user");
$pepper = "cxlkdawpoalsk";

$pass_encrypted = $salt.$pass_word.$pepper;
return $pass_encrypted;
}

 

my problem right now is when it's time the user login to the website.

Link to comment
Share on other sites

"In the meantime", as in "while you're reading that article and absorbing its knowledge", don't do anything with your script. If you've pushed it to production, take it down. Once you've read and understood the article, then go back and fix the script before uploading it again.

If you don't, then you're only causing problems for yourself and (what's worse) your users.

Link to comment
Share on other sites

I already had this snippet code in adding users

 

	if(isset($_POST['add_user'])){
	$passw = trim(htmlentities($_POST['password']));

	$encrypted = enc_salt($passw);

	$con = "true";
		$sql = "SELECT * FROM users WHERE username='".$_POST['user_name']."'";
		$result = $database->query($sql);
		$row = $database->fetch_array($result);

		if($row!=""){
			$con="false";
		}

	if($con!="false"){	
	 $sql  = "INSERT INTO photo_gallery.users (username, password, first_name, last_name)";
	$sql .= " VALUES ('".trim(htmlentities($_POST['user_name']))."','".$encrypted."', '".trim(htmlentities($_POST['first_name']))."', '".trim(htmlentities($_POST['last_name']))."')";

	$result_set = $database->query($sql);

	echo '<script type="text/javascript">alert("Account Created!");</script>';}
	else{
		echo '<script type="text/javascript">alert("This username already exist!");</script>';
	}
}

 

where my function enc_salt is:

function enc_salt($string){
//encrypting
$pass_word = sha1($string);
$salt = md5("user");
$pepper = "cxlkdawpoalsk";

$pass_encrypted = $salt.$pass_word.$pepper;
return $pass_encrypted;
}

 

my problem right now is when it's time the user login to the website.

 

Very ineffective salting method.

 

Try this:

function enc_salt($password) {
    $salt = 'somerandomecharacters1646#s@0-2 da2e/5ad+';
    return md5($password . $salt);
}

Link to comment
Share on other sites

Very ineffective salting method.

 

Try this:

function enc_salt($password) {
    $salt = 'somerandomecharacters1646#s@0-2 da2e/5ad+';
    return md5($password . $salt);
}

 

Yours is ineffective as well. Salts should be random and unique per user.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.