ng-password-strength icon indicating copy to clipboard operation
ng-password-strength copied to clipboard

Special characters

Open yourilefers opened this issue 9 years ago • 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).

yourilefers avatar Feb 02 '16 11:02 yourilefers

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.

Bitblade avatar Feb 24 '16 20:02 Bitblade

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.

Yongshuai-Liu avatar Jul 28 '16 23:07 Yongshuai-Liu

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.

BenWoodford avatar Dec 17 '16 14:12 BenWoodford