Page 1 of 1

md5 problem with input Field

Posted: Sat Aug 20, 2011 9:52 pm
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

Re: md5 problem with input Field

Posted: Sat Aug 20, 2011 11:18 pm
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

Re: md5 problem with input Field

Posted: Sun Aug 21, 2011 4:36 pm
by The-Marshall
Thanx for replay i will try your idea .