#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0

    New website, looking for registration code


    Hello. I am new to PHP and I want to add something to a website that I will be opening. Basically, I want to be able to have a code that does not allow a user to have the same password as their username. Can anyone help me?

    Thank you guys,
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    15
    Rep Power
    0
    check this link for adding user and validating user.

    ://php.thedemosite.co.uk/addausercode.php
  4. #3
  5. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,988
    Rep Power
    9397
    Then find the places where users register and where they change their passwords, and in the validation parts add a check that their username isn't the same as the password.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    thank you for the link. What I meant is the code that I add on registration page that prevent my customers to have a matching username and password.

    Cheers
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    48
    Rep Power
    3
    The easiest way to do this would be with JavaScript.

    You can check out this page by W3C to find out more about form validation.
    http://www.w3schools.com/js/js_form_validation.asp

    Here's an example tailored to your need:
    Code:
    <html>
        <head>
            <title>
                Example Page
            </title>
            <script type="text/javascript">
                function validateForm() {
                   if (document.forms["myForm"]["username"].value == document.forms["myForm"]["password"].value) {
                       // Display notification
                       document.getElementById('notification').innerHTML = 'Your username and password must be different.';
                       // You must return false to avoide actual form submission
                       return false;
                   }
                }
            </script>
        </head>
        <body>
            <span id="notification" style="color: red;"></span>
            <form method="post" action="myfile.php" name="myForm" onsubmit="return validateForm()" >
                <input type="text" name="username" id="username">
                <input type="text" name="password" id="password">
                <input type="submit" name="submit" id="submit">
            </form>
        </body>
    </html>
    Keep in mind...
    You must also perform this check in your PHP POST script if you want to enforce it. If you *only* perform the check with JavaScript, the user could just disable JavaScript to bypass it. JavaScript is just a nice way to give the user some instant feedback.
  10. #6
  11. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    What you're asking for isn't difficult to do; it just involves adding a simple if statement. It's really impossible to go into any more specific details without knowing exactly what your code looks like.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    4
    Rep Power
    0
    Okay. Thats make sense.
    Thank you so much
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2011
    Posts
    122
    Rep Power
    0

    New website, looking for registration code [split]


    hi

    Please find the answer.
    PHP Code:
    <?php
    include('config.php');
    $userName=mysql_real_escape_string($_POST['user_name']);
    $userPass=mysql_real_escape_string($_POST['user_password']);
    $errors=array();
    if(
    $userName === $userPass){
    $errors[]="Your UserName and Password must be different";
    }
    if(empty(
    $errors)){
     
    $query="insert query here...";
     
    $result=mysql_query($query);
    }else{
     foreach(
    $errors as $error){
      echo 
    $error.'<br>';
     }
    }
    mysql_close();   
    ?>
    [[ "phpnet" tags are for references to the online manual. use "php" tags for PHP code --requinix ]]

    Thanks
    diya
    Last edited by requinix; November 27th, 2012 at 02:21 PM.
  16. #9
  17. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,988
    Rep Power
    9397
    Originally Posted by diyaots
    Please find the answer.
    How are we supposed to do that when we don't even know the question?

    Comments on this post

    • msteudel agrees : lol
  18. #10
  19. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    if I understand him correctly, this is supposed to be a solution for the original thread.
  20. #11
  21. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,988
    Rep Power
    9397

IMN logo majestic logo threadwatch logo seochat tools logo