This react component aims to improve common issues in password field UX.
27 |Inspect element to see all your password info with debug mode on!
38 | 39 |
43 | npm install react-ux-password-field
44 |
45 | View it on Github
46 |
50 | // use it like any other react component.
51 | // just require and place it inside your render function.
52 |
53 | var InputPassword = require('react-ux-password-field');
54 |
55 | ...
56 |
57 | render: function() {
58 | return (
59 | <InputPassword />
60 | )
61 | }
62 |
63 |
64 | * React UX Password Field is UMD compatible, meaning it will load with 65 | commonJS, AMD/RequireJS, or standalone.
66 |Add your attributes normally like you would any password field. (id, placeholder, required, pattern etc...) But now you get the following extras:
69 |77 |
infoBar={false}
will disable the visible meter below the field.
78 | 79 | You can still rely on the attributes in the container class to do any other logic including. 80 |
81 |93 |
zxcvbn={false}
If false is passed. zxcvbn will be disabled. You can also pass an alternate source in a string to modify the async loaded source. default is: https://cdnjs.cloudflare.com/ajax/libs/zxcvbn/1.0/zxcvbn.min.js
94 |
95 | 96 | You can also pass "debug" as your string and it will console.log the zxcvbn object returned on each password change. 97 |
98 |99 | Note: zxcvbn is loaded async as it is a pretty big file. The async load time usually isn't an issue for a password usecase, if it is. Consider disabling and moving to a server-side load. 100 |
101 | 102 |106 |
minScore={2}
provides a password strength score based on 0-4. You can set the minimum accepted score for the field to be considered valid. Note: Dropbox who created and uses the library, does not set a minimum score, but does provide the info for the user.
107 |
108 |
109 | 112 |
statusColor="#5CE592"
will change the default valid color in the bar.
113 |
114 |
115 | 118 |
statusInactiveColor="#FC6F6F"
will change the default invalid color in the bar.
119 |
120 |
121 | 124 |
strengthLang={['Bad', 'Not good', 'Decent', 'Strong', 'Great']}
will modify the text shown next to the bar. You can pass an empty array to remove the text.
125 |
126 |
127 | 130 |
changeCb={funcName}
will call your callback on zxcvbn level change. It will pass in the old and new value. You can use this to hook other state related to the quality of the password if needed.
131 |
132 |
133 | 138 |
toggleMask={false}
will disable the temporarily unmasking password, and it will revert to acting like a normal password field which masks the entire time.
139 |
140 |
141 | 143 |
unMaskTime={1400}
will change the default length a password field is unmasked for. *This is debounced, so the count will only start when typing is paused.
144 |
145 |
146 | 152 |
minLength={7}
currently, the html5 spec only provides maxLength property. But react makes it easy to add a minLength as well. This can also easily be implemented with the pattern field.
153 |
154 |
155 | 156 | You can also use all the default HTML5 input validation attributes, like maxLength, pattern, required etc... 157 |
158 | 159 |162 | Pull requests are welcomed, please file an issue explaining the problem you're solving first, and pull-request to an upstream branch instead of master. 163 |
164 | 165 |