1,105,409 Community Members

Confirm Password and Password not equal to username

Member Avatar
cheelo007
Light Poster
31 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello, this one is probably really simple, but I am a noob... I just want the password confirmation function to work and I would also like the password to not equal the username.

I am running into a problem with how I set up the logic for my variables. Trying to fix my registration and login page. All the other logic statements work just fine.

Thank you.

<?php

class Register
{
  private $username;
  private $password;
  private $confirm_password;
  private $passmd5;
  private $email;
  private $errors;
  private $token;

  public function __construct()
  {
    $this->errors 			 = array();
    $this->username 		 = $this->filter($_POST['ruser']);
    $this->password 	         	 = $this->filter($_POST['rpass']);
    $this->confirm_password     = $this->filter($_POST['rconfirm_rpass']);
    $this->email    		         = $this->filter($_POST['remail']);
    $this->token  			 = $_POST['token'];
    $this->passmd5                   = md5($this->password);
  }

  public function process()
  {
    if($this->valid_token() && $this->valid_data())
         $this->register();

    return count($this->errors)? 0 : 1;
  }

  public function filter($var)
  {
    return preg_replace('/[^a-zA-Z0-9@.]/','',$var);
  }

  public function register()
  {
   mysql_connect("localhost","root","") or die(mysql_error());
   mysql_select_db("password") or die (mysql_error());

   mysql_query("INSERT INTO users(username,password) VALUES ('{$this->username}','{$this->passmd5}')");

   if(mysql_affected_rows()< 1)
     $this->errors[] = 'Could Not Process Form';
  }

  public function user_exists()
  {
  mysql_connect("localhost","root","") or die(mysql_error());
  mysql_select_db("password") or die (mysql_error());
  $data = mysql_query("SELECT ID FROM users WHERE username = '{$this->username}'");

  return mysql_num_rows($data)? 1 : 0;
  }

  public function show_errors()
  {
    echo "<h3>Errors</h3>";

    foreach($this->errors as $key=>$value)
      echo $value."<br>";
  }

  public function valid_data()
  {
    if($this->user_exists())
      $this->errors[] = 'Username Already Taken';
   
    if(empty($this->username))
      $this->errors[] = 'Invalid Username';
   
    if(empty($this->password))
      $this->errors[] = 'Invalid Password';
	
	if(($this->$password !== $this->$confirm_password))
      $this->errors[] = 'Passwords Must Match';
	
	if(($this->$username == $this->$password))
      $this->errors[] = 'Password Cannot Be Your Username';
   
    if(empty($this->email) || !eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$',$this->email))
      $this->errors[] = 'Invalid Email';
  return count($this->errors)? 0 : 1;
  }


  public function valid_token()
  {
   if(!isset($_SESSION['token']) || $this->token != $_SESSION['token'])
     $this->errors[] = 'Invalid Submission';

   return count($this->errors)? 0 : 1;
  }
}

?>
Member Avatar
jstfsklh211
Junior Poster
155 posts since Apr 2011
Reputation Points: 38 [?]
Q&As Helped to Solve: 35 [?]
Skill Endorsements: 2 [?]
 
0
 

replace

if(($this->$password !== $this->$confirm_password))
$this->errors[] = 'Passwords Must Match';

if(($this->$username == $this->$password))
$this->errors[] = 'Password Cannot Be Your Username';

with

if(($this->password !== $this->confirm_password))
$this->errors[] = 'Passwords Must Match';

if(($this->username == $this->password))
$this->errors[] = 'Password Cannot Be Your Username';
Member Avatar
cheelo007
Light Poster
31 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

replace

if(($this->$password !== $this->$confirm_password))
$this->errors[] = 'Passwords Must Match';

if(($this->$username == $this->$password))
$this->errors[] = 'Password Cannot Be Your Username';

with

if(($this->password !== $this->confirm_password))
$this->errors[] = 'Passwords Must Match';

if(($this->username == $this->password))
$this->errors[] = 'Password Cannot Be Your Username';

Whoops lol, I could have sworn I had that fixed earlier, but I get this error no matter if the variable was properly defined or not.

Fatal error: Cannot access empty property in /public_html/me-class.register.php on line 77

Member Avatar
jstfsklh211
Junior Poster
155 posts since Apr 2011
Reputation Points: 38 [?]
Q&As Helped to Solve: 35 [?]
Skill Endorsements: 2 [?]
 
0
 

Whoops lol, I could have sworn I had that fixed earlier, but I get this error no matter if the variable was properly defined or not.

Fatal error: Cannot access empty property in /public_html/me-class.register.php on line 77

post the line of code thats giving you the error

Member Avatar
cheelo007
Light Poster
31 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

post the line of code thats giving you the error

77. if(($this->$password !== $this->confirm_password))
78. $this->errors[] = 'Passwords Must Match';

79. if(($this->$username == $this->password))
80. $this->errors[] = 'Password Cannot Be Your Username';

Member Avatar
jstfsklh211
Junior Poster
155 posts since Apr 2011
Reputation Points: 38 [?]
Q&As Helped to Solve: 35 [?]
Skill Endorsements: 2 [?]
 
0
 

you only half way applied the last fix i gave you

when using class variables the syntax is $this->varName without the second '$'
you only changed it on one side of your comparisons

Member Avatar
cheelo007
Light Poster
31 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

you only half way applied the last fix i gave you

when using class variables the syntax is $this->varName without the second '$'
you only changed it on one side of your comparisons

Arrgh.. lol thank you very much. That fixed it!

Thanks again!

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: