zxcvbn.js 911 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* global zxcvbn */
  2. export class Zxcvbn {
  3. init(include) {
  4. this._include = include;
  5. }
  6. scorePassword(password, inputs) {
  7. // 0-4 score, the more the stronger password
  8. return zxcvbn(password, inputs).score;
  9. }
  10. load() {
  11. if (typeof zxcvbn === "undefined") {
  12. this._include.include('misago/js/zxcvbn.js');
  13. return this._loadingPromise();
  14. } else {
  15. return this._loadedPromise();
  16. }
  17. }
  18. _loadingPromise() {
  19. return new Promise(function(resolve) {
  20. var wait = function() {
  21. if (typeof zxcvbn === "undefined") {
  22. window.setTimeout(function() {
  23. wait();
  24. }, 200);
  25. } else {
  26. resolve();
  27. }
  28. };
  29. wait();
  30. });
  31. }
  32. _loadedPromise() {
  33. // we have already loaded zxcvbn.js, resolve away!
  34. return new Promise(function(resolve) {
  35. resolve();
  36. });
  37. }
  38. }
  39. export default new Zxcvbn();