Results 1 to 5 of 5

Thread: php ereg checking password and retype password

  1. #1
    Join Date
    Nov 2010
    Posts
    114
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default php ereg checking password and retype password

    Hi All,

    i wrote a code for checking password and retype password same or not .Iam unable to go further and make it work.Can anyone help me in this. This is my code

    I am getting this from register .html to validate.php. The below code belongs to validate.php.In Html i am just passing the value for these options.



    switch ($type) {
    case 'password':
    validatePassword($value);
    break;
    case 'repassword':
    validateRepassword($value);
    break;
    }


    function validatePassword($value) {
    if(ereg("[a-zA-Z0-9^,<>?/*()&^\%$#!~`]{4,9}$", $value, $regs)) // for some reason if i keep @ in the ereg expression it gives me error//
    {
    echo "true";
    } else {
    echo "false";
    }
    }

    function validateRepassword($value) {
    if(ereg("[a-zA-Z0-9^,<>?/*()&^\%$#!~`]{4,9}$", $value, $regs))
    {
    echo"true";
    validateCheck();
    }
    else {
    echo "false";
    }


    }

    Now how can i check if both are same or not and how can i check the ereg expression for address field which can accept any type of character
    Last edited by hemi519; 01-20-2011 at 08:40 AM.

  2. #2
    Join Date
    Nov 2008
    Posts
    58
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Default

    how can i check if both are same or not
    like this:
    Code:
    if($pwd != $re_pwd)
    {
    //error
    }
    for address field which can accept any type of character
    if it can accept any value why validate on the characters? You can do an empty check and a max length check.

    Also see this form validation page

  3. The Following User Says Thank You to prasanthmj For This Useful Post:

    hemi519 (01-21-2011)

  4. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    About the @ symbol - did you try escaping it?

    \@

    instead of:

    @

    and where you have:

    \%

    are you escaping the % character? If not, it should be:

    \\%

    BTW, you should use preg_match, not ereg. But as long as your system accepts ereg, that's a fine point for now.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #4
    Join Date
    Jan 2011
    Location
    QLD, Australia
    Posts
    23
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    Yeah I agree with John, ereg & eregi have been deprecated since PHP 5.0.3
    so you should use preg_match instead for compatability sake.

    Something like below(password must be min 4 to max 9 characters, change to suit);

    PHP Code:
    function checkPassword($value){
    return 
    preg_match('/^[- a-z0-9,<>@()&\%$#!~`]{4,9}$/i'$value) ? $value false;
    }

    $pass1 checkPassword(trim($_POST['password1']));
    $pass2 trim($_POST['password2']);


    if(
    $pass1){

      if(
    $pass1 === $pass2){
      echo 
    'Passwords match';
      }
      else{
      echo 
    'Passwords donot match';
      }
    }
    else{
    echo 
    'Invalid characters in password etc...';

    I haven't included all the special characters as I cannot see much point of checking if you are going to allow all characters? but you could easily modify this to suit yourself, just be careful with brackets []{} you will need to escape these with a backslash.
    Last edited by Oziam; 01-22-2011 at 06:44 AM.

  6. #5
    Join Date
    Nov 2010
    Posts
    114
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your suggestions but still iam unable to work as i wanted. So i am posting my code

    Below is all my code and i can not change anything in validate.php. I am still unable to check, if password and confirm password are same. The other thing is index.html by default the submit button will be enabled but when i click on any filed and it is wrong it becomes as disable. what i want is when the page is loaded it should be disable and if all the fields are correct then it should be enable. Hope that is possible but i am unable to make it.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •