Custom password requirements on forgot password/ password recovery - Parse.com

815 views Asked by At

I have an iOS app, and using Parse.com, I can allow the user to reset their if they forget it using the Parse.com API. The problem lies in the fact that when the user resets their password, none of the criteria for the password can be enforced (or at least I haven't found a way yet) or even another field to verify you enter in the correct password. I'm wondering if anyone out there has had a solution to this.

My situation exactly: When you type your reset password in, can I apply minimum criteria such as 1 Capital letter, 1 number, and 1 lowercase letter? In addition, have a verify password field below.

I've tried to do client-side JS validation with no success. I've included the code blocks below. Thank you!!!!

HTML

<div class="row">
<div class="medium-6 medium-offset-3 small-10 small-offset-1 columns">
  <form id='form' action='#' method='POST'>
    <label>New Password for <span id='username_label'></span></label>
    <input name="new_password" type="password" />
    <input name='utf-8' type='hidden' value='✓' />
    <input name="username" id="username" type="hidden" />
    <input name="token" id="token" type="hidden" />
    <button>Change Password</button>
  </form>
</div>

JS

<script language='javascript' type='text/javascript'>
<!--
window.onload = function() {
  var urlParams = {};
  (function () {
      var pair, // Really a match. Index 0 is the full match; 1 & 2 are the key & val.
          tokenize = /([^&=]+)=?([^&]*)/g,
          // decodeURIComponents escapes everything but will leave +s that should be ' '
          re_space = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); },
          // Substring to cut off the leading '?'
          querystring = window.location.search.substring(1);

      while (pair = tokenize.exec(querystring))
         urlParams[re_space(pair[1])] = re_space(pair[2]);
  })();

  var base = 'https://www.parse.com';
  var id = urlParams['id'];
  document.getElementById('form').setAttribute('action', base + '/apps/' + id + '/request_password_reset');
  document.getElementById('username').value = urlParams['username'];
  document.getElementById('username_label').appendChild(document.createTextNode(urlParams['username']));

  document.getElementById('token').value = urlParams['token'];
  if (urlParams['error']) {
    document.getElementById('error').appendChild(document.createTextNode(urlParams['error']));
  }
  if (urlParams['app']) {
    document.getElementById('app').appendChild(document.createTextNode(' for ' + urlParams['app']));
  }

}

$(function() {
$('#form').submit(function() {
    if (document.getElementById('new_password').length == 2)
    {
      // something is wrong
      alert('There is a problem with the first field');
      return false;
    }
    else {
      return true;
    }
  });

});

//-->

0

There are 0 answers