subarroca/ng-password-strength

Special characters

yourilefers opened this issue · 3 comments

When the password contains generated special characters (like '('), it crashed. We had to implemented something like this:

http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex

on line 133 of the 0.2 version. I have no idea wether this has been fixed in 0.3, because bower could not fetch that version. That version has also not yet been 'compiled' (minified).

Be warned, the 0.2 version contains a lot of gotcha's. For instance, the progressbar is blue instead of red for weak passwords because the wrong classes are used. (Line 183/184, the error is obvious when comparing to the lines below) It also tends to ignore a lot of special characters because it uses a regex with a very limited subset of special characters. I believe I fixed that by using regexes like /\W|_/g

After some difficulty with (very) outdated dependencies, I just managed to get the 0.3 version working, which still contains the escape issue.

To fix special char bug:
1 . Add this function.
function escapeRegExp(str) {
return str.replace(/[-[]/{}()*+?.^$|]/g, "$&");
}

2. Update line 133 to var _reg = new RegExp(escapeRegExp(_p[i]), 'g');

To fix the blue color bar bug:

  1. Update line 183/184 to
    outter: scope.outterClassPrefix + 'danger',
    inner: scope.innerClassPrefix + 'danger'

Cheers.

I found @YoshiDatoutou's solution wasn't working for me, I suspect it's GitHub messing with the formatting though:

.replace(/[\\\-\[\]\/\{\}\(\)\*\+\?\.\^\$\|]/g, "\$&")

was the line I had to use.