Web Analytics Made Easy -
StatCounter Password and confirm password input fields - CodingForum

Announcement

Collapse
No announcement yet.

Password and confirm password input fields

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Password and confirm password input fields

    Hello,

    I know how to make two input fields where the user is asked to enter a password and my question is how can I make a comparison between the text in the first field and in the second field to make sure that both passwords are the same?

    Cheers

  • #2
    That depends on which server side language you are using to validate the form.

    You can also do the comparison in the browser using JavaScript but that doesn't do away with the server side validation.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

    Comment


    • #3
      Hi,

      <input type="password" ng-model="pwd"/><input type="password" ng-model="confirmPwd" ng-blur="checkPwd()"/>

      JS:

      $scope.checkPwd(){

      if($scope.pwd !== $scope.confirmPwd) { //Do validation stuff }

      }

      Hope this will be helpful

      Thanks,
      Mobile App Development Company

      Comment


      • #4
        Don't forget to include the server side validation - people can turn off JavaScript.
        Stephen
        Learn Modern JavaScript - http://javascriptexample.net/
        Helping others to solve their computer problem at http://www.felgall.com/

        Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

        Comment


        • #5
          Originally posted by felgall View Post
          Don't forget to include the server side validation - people can turn off JavaScript.
          Or intentionally bypass it... which is what most crackers do. Part of why I like to include a hash with each form to prevent resubmit or re-use without first requesting a copy of the form. All you need is some joker walking up, hitting "back" a few times, hit submit, and boom, free lulz.

          ANYTHING you do client side -- form element name attributes, values passed as hidden, scripted or HTML validation -- CANNOT be trusted server-side and should be checked again before pressing on, and if anything is suspect, spit it back at the user.
          Walk the dark path, sleep with angels, call the past for help.
          https://cutcodedown.com
          https://medium.com/@deathshadow

          Comment


          • #6
            Form validation with JavaScript is seldom even necessary any more. Once you have pattern attributes on the inputs to provide some HTML validation then that is generally good enough to leave the rest of the validation for the server. Ypu can't check the passwords match with that attribute but you can check that the passwords meet your minimum length criteria (there shouldn't be a maximum as password_hash makes all of them the same size on the server) just leaving the check that they are the same on the server.

            Better yet if you don't have concerns about someone actually seeing the password over the shoulder of the person setting it then just have them enter it once as plain text - type="password" only hides it from anyone who can only see the screen and not the keyboard.
            Stephen
            Learn Modern JavaScript - http://javascriptexample.net/
            Helping others to solve their computer problem at http://www.felgall.com/

            Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

            Comment

            Working...
            X