md5 problem with input Field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
The-Marshall
Forum Newbie
Posts: 2
Joined: Sat Aug 20, 2011 9:39 pm

md5 problem with input Field

Post by The-Marshall »

Hi everyone
my problem is :
i have 3 input field 1- username, 2- pass, 3- repass
so i want to edit my username only , and when i edit my username also my pass edit automatically because my input field is empty
and with md5 make the encrypt to empty field :banghead:
this is the code :

Code: Select all

<form action="empty.php" method="post">
<input type="password" name="pass" /><br />
<input type="password" name="repass" /><br />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST['submit'])){
$pass    = md5($_POST["pass"]);
$repass  = md5($_POST["repass"]);
if ((strlen(trim(!empty($pass))) > 0) and (strlen(trim(!empty($repass))) > 0)) {
//if (isset($pass) and isset($repass)){
  echo"Not empty <br />";
  echo $pass."<br />";
  echo $repass."<br />";
}else{
  echo"Empty";
}
}
?>
can anyone solve my problem
Thanx in advance
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: md5 problem with input Field

Post by twinedev »

Try something like this, if I understand what you are looking for...

Code: Select all

<form action="empty.php" method="post">
	<input type="password" name="pass" /><br />
	<input type="password" name="repass" /><br />
	<input type="submit" name="submit" />
</form>
<?php
	if(isset($_POST['submit'])){
		// Trims all string $_POST values
		foreach($_POST as $key=>$val) { if (is_string($val)) { $_POST[$key] = trim($val); } }

		if ($_POST['pass']=='' && $_POST['repass']=='') {
			// Both fields were left empty, so assume only username is being changed
		}
		else {
			// Something was entered, so do some checking to make sure valid size / repass=pass
		}
	}
?>
(also be prepared for the discussion of that you should use something stronger than md5, and that using md5 is not actually encryption, both which are valid points to look into before you use this in production) :)

-Greg
The-Marshall
Forum Newbie
Posts: 2
Joined: Sat Aug 20, 2011 9:39 pm

Re: md5 problem with input Field

Post by The-Marshall »

Thanx for replay i will try your idea .
Post Reply