@createnl/secure-password-input
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -1,4 +0,34 @@ | ||
import React from 'react'; | ||
import './Button.css'; | ||
const Button = ({ type = 'button', text, className = '', children, ...buttonProps }) => (React.createElement("button", Object.assign({}, buttonProps, { type: type, title: children ? text : undefined, className: `spi-button ${className}` }), children || text)); | ||
export default Button; | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importDefault(require("react")); | ||
require("./Button.css"); | ||
var Button = function (_a) { | ||
var _b = _a.type, type = _b === void 0 ? 'button' : _b, text = _a.text, _c = _a.className, className = _c === void 0 ? '' : _c, children = _a.children, buttonProps = __rest(_a, ["type", "text", "className", "children"]); | ||
return (react_1.default.createElement("button", __assign({}, buttonProps, { type: type, title: children ? text : undefined, className: "spi-button " + className }), children || text)); | ||
}; | ||
exports.default = Button; |
@@ -1,12 +0,18 @@ | ||
import React from 'react'; | ||
import { IconVisibilityOff, IconVisibilityOn } from './set'; | ||
import './Icon.css'; | ||
const icons = { | ||
'visibility-off': IconVisibilityOff, | ||
'visibility-on': IconVisibilityOn, | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
const Icon = ({ name, className = '' }) => { | ||
const IconComponent = icons[name] ? icons[name] : null; | ||
return IconComponent ? React.createElement(IconComponent, { className: `spi-icon ${className}` }) : null; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importDefault(require("react")); | ||
var set_1 = require("./set"); | ||
require("./Icon.css"); | ||
var icons = { | ||
'visibility-off': set_1.IconVisibilityOff, | ||
'visibility-on': set_1.IconVisibilityOn, | ||
}; | ||
export default Icon; | ||
var Icon = function (_a) { | ||
var name = _a.name, _b = _a.className, className = _b === void 0 ? '' : _b; | ||
var IconComponent = icons[name] ? icons[name] : null; | ||
return IconComponent ? react_1.default.createElement(IconComponent, { className: "spi-icon " + className }) : null; | ||
}; | ||
exports.default = Icon; |
@@ -1,6 +0,14 @@ | ||
import React from 'react'; | ||
const IconVisibilityOff = ({ className = '' }) => (React.createElement("svg", { viewBox: "0 0 283.7 245", className: className }, | ||
React.createElement("path", { d: "M141.8,51.6c35.6,0,64.5,28.9,64.5,64.5c0,8.3-1.7,16.2-4.6,23.5l37.8,37.8c19.3-16.1,34.8-37.3,44.2-61.2c-22.3-56.6-77.4-96.7-141.8-96.7c-18.1,0-35.3,3.2-51.6,9l28,27.7C125.6,53.3,133.4,51.6,141.8,51.6z" }), | ||
React.createElement("path", { d: "M139.6,77.4l40.9,40.7c0-0.6,0-1.4,0-2.1c0-21.4-17.3-38.7-38.7-38.7C141.1,77.4,140.4,77.4,139.6,77.4" }), | ||
React.createElement("path", { d: "M29.3,0L12.9,16.4l29.4,29.4l5.8,5.8C26.8,68.3,10.1,90.3,0,116c22.3,56.6,77.4,96.7,141.8,96.7c20,0,39.1-3.9,56.5-10.8l5.5,5.4l37.6,37.6l16.4-16.4L29.3,0z M141.8,180.5c-35.6,0-64.5-28.9-64.5-64.5c0-10.2,2.6-19.7,6.8-28.4l20,20c-0.6,2.7-1,5.4-1,8.4c0,21.4,17.3,38.7,38.7,38.7c2.8,0,5.7-0.4,8.4-1l20,20C161.6,177.9,152,180.5,141.8,180.5z" }))); | ||
export default IconVisibilityOff; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importDefault(require("react")); | ||
var IconVisibilityOff = function (_a) { | ||
var _b = _a.className, className = _b === void 0 ? '' : _b; | ||
return (react_1.default.createElement("svg", { viewBox: "0 0 283.7 245", className: className }, | ||
react_1.default.createElement("path", { d: "M141.8,51.6c35.6,0,64.5,28.9,64.5,64.5c0,8.3-1.7,16.2-4.6,23.5l37.8,37.8c19.3-16.1,34.8-37.3,44.2-61.2c-22.3-56.6-77.4-96.7-141.8-96.7c-18.1,0-35.3,3.2-51.6,9l28,27.7C125.6,53.3,133.4,51.6,141.8,51.6z" }), | ||
react_1.default.createElement("path", { d: "M139.6,77.4l40.9,40.7c0-0.6,0-1.4,0-2.1c0-21.4-17.3-38.7-38.7-38.7C141.1,77.4,140.4,77.4,139.6,77.4" }), | ||
react_1.default.createElement("path", { d: "M29.3,0L12.9,16.4l29.4,29.4l5.8,5.8C26.8,68.3,10.1,90.3,0,116c22.3,56.6,77.4,96.7,141.8,96.7c20,0,39.1-3.9,56.5-10.8l5.5,5.4l37.6,37.6l16.4-16.4L29.3,0z M141.8,180.5c-35.6,0-64.5-28.9-64.5-64.5c0-10.2,2.6-19.7,6.8-28.4l20,20c-0.6,2.7-1,5.4-1,8.4c0,21.4,17.3,38.7,38.7,38.7c2.8,0,5.7-0.4,8.4-1l20,20C161.6,177.9,152,180.5,141.8,180.5z" }))); | ||
}; | ||
exports.default = IconVisibilityOff; |
@@ -1,5 +0,13 @@ | ||
import React from 'react'; | ||
const IconVisibilityOn = ({ className = '' }) => (React.createElement("svg", { viewBox: "0 0 283.7 193.4", className: className }, | ||
React.createElement("circle", { cx: "141.8", cy: "96.7", r: "38.7" }), | ||
React.createElement("path", { d: "M141.8,0C77.4,0,22.3,40.1,0,96.7c22.3,56.6,77.4,96.7,141.8,96.7s119.5-40.1,141.8-96.7C261.4,40.1,206.3,0,141.8,0z M141.8,161.2c-35.6,0-64.5-28.9-64.5-64.5c0-35.6,28.9-64.5,64.5-64.5s64.5,28.9,64.5,64.5C206.3,132.3,177.4,161.2,141.8,161.2z" }))); | ||
export default IconVisibilityOn; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importDefault(require("react")); | ||
var IconVisibilityOn = function (_a) { | ||
var _b = _a.className, className = _b === void 0 ? '' : _b; | ||
return (react_1.default.createElement("svg", { viewBox: "0 0 283.7 193.4", className: className }, | ||
react_1.default.createElement("circle", { cx: "141.8", cy: "96.7", r: "38.7" }), | ||
react_1.default.createElement("path", { d: "M141.8,0C77.4,0,22.3,40.1,0,96.7c22.3,56.6,77.4,96.7,141.8,96.7s119.5-40.1,141.8-96.7C261.4,40.1,206.3,0,141.8,0z M141.8,161.2c-35.6,0-64.5-28.9-64.5-64.5c0-35.6,28.9-64.5,64.5-64.5s64.5,28.9,64.5,64.5C206.3,132.3,177.4,161.2,141.8,161.2z" }))); | ||
}; | ||
exports.default = IconVisibilityOn; |
@@ -1,3 +0,9 @@ | ||
import IconVisibilityOff from './IconVisibilityOff'; | ||
import IconVisibilityOn from './IconVisibilityOn'; | ||
export { IconVisibilityOff, IconVisibilityOn, }; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var IconVisibilityOff_1 = __importDefault(require("./IconVisibilityOff")); | ||
exports.IconVisibilityOff = IconVisibilityOff_1.default; | ||
var IconVisibilityOn_1 = __importDefault(require("./IconVisibilityOn")); | ||
exports.IconVisibilityOn = IconVisibilityOn_1.default; |
@@ -1,5 +0,13 @@ | ||
import Button from './Button/Button'; | ||
import Icon from './Icon/Icon'; | ||
import Input from './Input/Input'; | ||
import InputLabel from './InputLabel/InputLabel'; | ||
export { Button, Icon, Input, InputLabel, }; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Button_1 = __importDefault(require("./Button/Button")); | ||
exports.Button = Button_1.default; | ||
var Icon_1 = __importDefault(require("./Icon/Icon")); | ||
exports.Icon = Icon_1.default; | ||
var Input_1 = __importDefault(require("./Input/Input")); | ||
exports.Input = Input_1.default; | ||
var InputLabel_1 = __importDefault(require("./InputLabel/InputLabel")); | ||
exports.InputLabel = InputLabel_1.default; |
@@ -1,4 +0,38 @@ | ||
import React, { forwardRef, } from 'react'; | ||
import './Input.css'; | ||
const Input = forwardRef(({ type, value, defaultValue, className = '', ...inputProps }, ref) => (React.createElement("input", Object.assign({}, inputProps, { ref: ref, type: type || 'text', defaultValue: !value ? defaultValue : undefined, className: `spi-input ${className}` })))); | ||
export default Input; | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importStar(require("react")); | ||
require("./Input.css"); | ||
var Input = react_1.forwardRef(function (_a, ref) { | ||
var type = _a.type, value = _a.value, defaultValue = _a.defaultValue, _b = _a.className, className = _b === void 0 ? '' : _b, inputProps = __rest(_a, ["type", "value", "defaultValue", "className"]); | ||
return (react_1.default.createElement("input", __assign({}, inputProps, { ref: ref, type: type || 'text', defaultValue: !value ? defaultValue : undefined, className: "spi-input " + className }))); | ||
}); | ||
exports.default = Input; |
@@ -1,4 +0,12 @@ | ||
import React from 'react'; | ||
import './InputLabel.css'; | ||
const InputLabel = ({ text, className = '' }) => (React.createElement("div", { className: `spi-input-label ${className}` }, text)); | ||
export default InputLabel; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importDefault(require("react")); | ||
require("./InputLabel.css"); | ||
var InputLabel = function (_a) { | ||
var text = _a.text, _b = _a.className, className = _b === void 0 ? '' : _b; | ||
return (react_1.default.createElement("div", { className: "spi-input-label " + className }, text)); | ||
}; | ||
exports.default = InputLabel; |
@@ -1,3 +0,9 @@ | ||
import PasswordInput from './PasswordInput/PasswordInput'; | ||
import SecurePasswordInput from './SecurePasswordInput/SecurePasswordInput'; | ||
export { PasswordInput, SecurePasswordInput, }; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var PasswordInput_1 = __importDefault(require("./PasswordInput/PasswordInput")); | ||
exports.PasswordInput = PasswordInput_1.default; | ||
var SecurePasswordInput_1 = __importDefault(require("./SecurePasswordInput/SecurePasswordInput")); | ||
exports.SecurePasswordInput = SecurePasswordInput_1.default; |
@@ -1,17 +0,49 @@ | ||
import React, { forwardRef, useState, } from 'react'; | ||
import { Button, Icon, Input, InputLabel, } from '../../components'; | ||
import './PasswordInput.css'; | ||
const PasswordInput = forwardRef(({ label, hideLabel = false, tabIndex, disabled, onChange, className = '', ...inputProps }, ref) => { | ||
const [passwordIsVisible, togglePasswordVisibility] = useState(false); | ||
const toggleVisibility = () => togglePasswordVisibility(!passwordIsVisible); | ||
const handleChange = (event) => { | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importStar(require("react")); | ||
var components_1 = require("../../components"); | ||
require("./PasswordInput.css"); | ||
var PasswordInput = react_1.forwardRef(function (_a, ref) { | ||
var label = _a.label, _b = _a.hideLabel, hideLabel = _b === void 0 ? false : _b, tabIndex = _a.tabIndex, disabled = _a.disabled, onChange = _a.onChange, _c = _a.className, className = _c === void 0 ? '' : _c, inputProps = __rest(_a, ["label", "hideLabel", "tabIndex", "disabled", "onChange", "className"]); | ||
var _d = react_1.useState(false), passwordIsVisible = _d[0], togglePasswordVisibility = _d[1]; | ||
var toggleVisibility = function () { return togglePasswordVisibility(!passwordIsVisible); }; | ||
var handleChange = function (event) { | ||
onChange(event.currentTarget.value); | ||
}; | ||
return (React.createElement("label", { "aria-label": hideLabel ? label : undefined, className: className }, | ||
!hideLabel && (React.createElement(InputLabel, { text: label, className: "custom-spi__label" })), | ||
React.createElement("div", { className: "spi__field-container" }, | ||
React.createElement(Input, Object.assign({}, inputProps, { ref: ref, type: passwordIsVisible ? 'text' : 'password', tabIndex: tabIndex, disabled: disabled, onChange: handleChange, className: "custom-spi__input" })), | ||
React.createElement(Button, { text: passwordIsVisible ? 'Verberg wachtwoord' : 'Toon wachtwoord', tabIndex: tabIndex, disabled: disabled, onClick: toggleVisibility, className: "custom-spi__button" }, | ||
React.createElement(Icon, { name: `visibility-${passwordIsVisible ? 'on' : 'off'}`, className: "custom-spi__button-icon" }))))); | ||
return (react_1.default.createElement("label", { "aria-label": hideLabel ? label : undefined, className: className }, | ||
!hideLabel && (react_1.default.createElement(components_1.InputLabel, { text: label, className: "custom-spi__label" })), | ||
react_1.default.createElement("div", { className: "spi__field-container" }, | ||
react_1.default.createElement(components_1.Input, __assign({}, inputProps, { ref: ref, type: passwordIsVisible ? 'text' : 'password', tabIndex: tabIndex, disabled: disabled, onChange: handleChange, className: "custom-spi__input" })), | ||
react_1.default.createElement(components_1.Button, { text: passwordIsVisible ? 'Verberg wachtwoord' : 'Toon wachtwoord', tabIndex: tabIndex, disabled: disabled, onClick: toggleVisibility, className: "custom-spi__button" }, | ||
react_1.default.createElement(components_1.Icon, { name: "visibility-" + (passwordIsVisible ? 'on' : 'off'), className: "custom-spi__button-icon" }))))); | ||
}); | ||
export default PasswordInput; | ||
exports.default = PasswordInput; |
@@ -1,2 +0,4 @@ | ||
export const immigrantSurnames = [ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.immigrantSurnames = [ | ||
'Yilmaz', | ||
@@ -103,3 +105,3 @@ 'Nguyen', | ||
]; | ||
export const nativeSurnames = [ | ||
exports.nativeSurnames = [ | ||
'de Jong', | ||
@@ -222,3 +224,3 @@ 'Jansen', | ||
]; | ||
export const dictionaryWords = [ | ||
exports.dictionaryWords = [ | ||
'aan', 'aanbod', 'aanraken', 'aanval', 'aap', 'aardappel', 'aarde', 'aardig', 'acht', 'achter', 'actief', 'activiteit', 'ademen', 'af', 'afgelopen', 'afhangen', 'afmaken', 'afname', 'afspraak', 'afval', 'al', 'algemeen', 'alleen', 'alles', 'als', 'alsjeblieft', 'altijd', 'ander', 'andere', 'anders', 'angst', 'antwoord', 'antwoorden', 'appel', 'arm', 'auto', 'avond', 'avondeten', | ||
@@ -225,0 +227,0 @@ 'baan', 'baby', 'bad', 'bal', 'bang', 'bank', 'basis', 'bed', 'bedekken', 'bedreiging', 'bedreven', 'been', 'beer', 'beest', 'beetje', 'begin', 'begrijpen', 'begrip', 'behalve', 'beide', 'beker', 'bel', 'belangrijk', 'bellen', 'belofte', 'beneden', 'benzine', 'berg', 'beroemd', 'beroep', 'bescherm', 'beslissen', 'best', 'betalen', 'beter', 'bevatten', 'bewegen', 'bewolkt', 'bezoek', 'bibliotheek', 'bieden', 'bij', 'bijna', 'bijten', 'bijvoorbeeld', 'bijzonder', 'binnen', 'binnenkort', 'blad', 'blauw', 'blazen', 'blij', 'blijven', 'bloed', 'bloem', 'bodem', 'boek', 'boerderij', 'boete', 'boom', 'boon', 'boord', 'boos', 'bord', 'borstelen', 'bos', 'bot', 'bouwen', 'boven', 'branden', 'brandstof', 'breed', 'breken', 'brengen', 'brief', 'broer', 'broek', 'brood', 'brug', 'bruikbaar', 'bruiloft', 'bruin', 'bui', 'buiten', 'bureau', 'buren', 'bus', 'buurman', 'buurvrouw', |
@@ -1,18 +0,23 @@ | ||
import zxcvbn from 'zxcvbn'; | ||
import { dictionaryWords, immigrantSurnames, nativeSurnames } from './commonOccurrences'; | ||
import { dutchTranslations, Feedback, feedbackTypes } from './translations'; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var zxcvbn_1 = __importDefault(require("zxcvbn")); | ||
var commonOccurrences_1 = require("./commonOccurrences"); | ||
var translations_1 = require("./translations"); | ||
// Transform any given string to a lowercase one without spaces | ||
const cleanUpString = (str) => str | ||
var cleanUpString = function (str) { return str | ||
.replace(/ /g, '') | ||
.toLowerCase(); | ||
.toLowerCase(); }; | ||
// Translate feedback to the Dutch language | ||
export const translate = (phrase) => { | ||
const feedback = feedbackTypes[phrase]; | ||
return dutchTranslations[feedback] || ''; | ||
exports.translate = function (phrase) { | ||
var feedback = translations_1.feedbackTypes[phrase]; | ||
return translations_1.dutchTranslations[feedback] || ''; | ||
}; | ||
// Check if given password contains a common Dutch dictionary word | ||
const checkIfPasswordContainsCommonWords = (password) => { | ||
const cleanPassword = cleanUpString(password); | ||
for (let i = 0; i < dictionaryWords.length; i += 1) { | ||
if (cleanPassword === dictionaryWords[i]) { | ||
var checkIfPasswordContainsCommonWords = function (password) { | ||
var cleanPassword = cleanUpString(password); | ||
for (var i = 0; i < commonOccurrences_1.dictionaryWords.length; i += 1) { | ||
if (cleanPassword === commonOccurrences_1.dictionaryWords[i]) { | ||
return true; | ||
@@ -24,6 +29,6 @@ } | ||
// Check if given password contains a common Dutch surname | ||
const checkIfPasswordContainsCommonName = (password) => { | ||
const cleanPassword = cleanUpString(password); | ||
for (let i = 0; i < nativeSurnames.length; i += 1) { | ||
const cleanSurname = cleanUpString(nativeSurnames[i]); | ||
var checkIfPasswordContainsCommonName = function (password) { | ||
var cleanPassword = cleanUpString(password); | ||
for (var i = 0; i < commonOccurrences_1.nativeSurnames.length; i += 1) { | ||
var cleanSurname = cleanUpString(commonOccurrences_1.nativeSurnames[i]); | ||
if (cleanPassword === cleanSurname) { | ||
@@ -33,4 +38,4 @@ return true; | ||
} | ||
for (let i = 0; i < immigrantSurnames.length; i += 1) { | ||
const cleanSurname = cleanUpString(immigrantSurnames[i]); | ||
for (var i = 0; i < commonOccurrences_1.immigrantSurnames.length; i += 1) { | ||
var cleanSurname = cleanUpString(commonOccurrences_1.immigrantSurnames[i]); | ||
if (cleanPassword === cleanSurname) { | ||
@@ -43,6 +48,6 @@ return true; | ||
// Get a score, from 0 up to and including 4, that determines the given password's strength | ||
export const getStrength = (password) => { | ||
const { score } = zxcvbn(password); | ||
const commonWordMatch = checkIfPasswordContainsCommonWords(password) ? 0 : 4; | ||
const surnameMatch = checkIfPasswordContainsCommonName(password) ? 0 : 4; | ||
exports.getStrength = function (password) { | ||
var score = zxcvbn_1.default(password).score; | ||
var commonWordMatch = checkIfPasswordContainsCommonWords(password) ? 0 : 4; | ||
var surnameMatch = checkIfPasswordContainsCommonName(password) ? 0 : 4; | ||
// Retrieve lowest score | ||
@@ -52,3 +57,3 @@ return [score, commonWordMatch, surnameMatch].sort()[0]; | ||
// Get textual feedback based on the given password's strength | ||
export const getStrengthFeedback = (strength) => { | ||
exports.getStrengthFeedback = function (strength) { | ||
switch (strength) { | ||
@@ -64,19 +69,19 @@ default: | ||
// Get a translated warning if the given password is not secure enough | ||
export const getWarning = (password) => { | ||
const { feedback } = zxcvbn(password); | ||
const defaultWarning = feedback.warning; | ||
const commonWordMatch = checkIfPasswordContainsCommonWords(password) | ||
? dutchTranslations[Feedback.warningDictionaryMatch] | ||
exports.getWarning = function (password) { | ||
var feedback = zxcvbn_1.default(password).feedback; | ||
var defaultWarning = feedback.warning; | ||
var commonWordMatch = checkIfPasswordContainsCommonWords(password) | ||
? translations_1.dutchTranslations[translations_1.Feedback.warningDictionaryMatch] | ||
: ''; | ||
const surnameMatch = checkIfPasswordContainsCommonName(password) | ||
? dutchTranslations[Feedback.warningCommonName] | ||
var surnameMatch = checkIfPasswordContainsCommonName(password) | ||
? translations_1.dutchTranslations[translations_1.Feedback.warningCommonName] | ||
: ''; | ||
const translatedWarning = translate(defaultWarning); | ||
var translatedWarning = exports.translate(defaultWarning); | ||
return translatedWarning || commonWordMatch || surnameMatch; | ||
}; | ||
// Get translated suggestions to provide user with tips on how to improve their given password | ||
export const getSuggestions = (password) => { | ||
const result = zxcvbn(password); | ||
const { suggestions } = result.feedback; | ||
return suggestions.map(suggestion => translate(suggestion)); | ||
exports.getSuggestions = function (password) { | ||
var result = zxcvbn_1.default(password); | ||
var suggestions = result.feedback.suggestions; | ||
return suggestions.map(function (suggestion) { return exports.translate(suggestion); }); | ||
}; |
@@ -1,2 +0,5 @@ | ||
export var Feedback; | ||
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Feedback; | ||
(function (Feedback) { | ||
@@ -30,4 +33,4 @@ Feedback[Feedback["suggestionAddMoreWords"] = 0] = "suggestionAddMoreWords"; | ||
Feedback[Feedback["warningTop100Password"] = 26] = "warningTop100Password"; | ||
})(Feedback || (Feedback = {})); | ||
export const feedbackTypes = { | ||
})(Feedback = exports.Feedback || (exports.Feedback = {})); | ||
exports.feedbackTypes = { | ||
'A word by itself is easy to guess': Feedback.warningDictionaryMatch, | ||
@@ -61,30 +64,30 @@ 'Add another word or two. Uncommon words are better.': Feedback.suggestionAddMoreWords, | ||
}; | ||
export const dutchTranslations = { | ||
[Feedback.suggestionAddMoreWords]: 'Voeg nog een aantal woorden toe. Ongebruikelijke woorden zijn beter', | ||
[Feedback.suggestionAllUppercaseNoImprovement]: 'Wachtwoorden met enkel hoofdletters zijn niet veilig dan wachtwoorden met enkel kleine letters, per se', | ||
[Feedback.suggestionAvoidAssociatedDates]: 'Vermijd datums en jaartallen die met jou te maken hebben', | ||
[Feedback.suggestionAvoidAssociatedYears]: 'Vermijd jaartallen die met jou te maken hebben', | ||
[Feedback.suggestionAvoidRecentYears]: 'Vermijd recente jaartallen', | ||
[Feedback.suggestionAvoidRepeats]: 'Vermijd herhaalde woorden of tekens', | ||
[Feedback.suggestionAvoidSequences]: 'Vermijd reeksen van tekens', | ||
[Feedback.suggestionIncreaseKeyboardPattern]: 'Gebruik een langer toetsenbord patroon met meerdere bochten', | ||
[Feedback.suggestionIncreaseWords]: 'Gebruik een aantal woorden, vermijd bekende termen', | ||
[Feedback.suggestionPredictableSubstitutions]: 'Voorspelbare vervangers, zoals \'@\' voor een \'a\', helpen niet echt', | ||
[Feedback.suggestionReversedWords]: 'Omgekeerde woorden zijn niet moeilijker te raden, per se', | ||
[Feedback.suggestionUnnecessaryCapitalization]: 'Hoofdlettergebruik helpt niet echt', | ||
[Feedback.suggestionUnnecessaryCharacters]: 'Symbolen, nummers of hoofdletters zijn niet nodig, per se', | ||
[Feedback.warningCommonName]: 'Veelvoorkomende voor- en achternamen zijn makkelijk te raden', | ||
[Feedback.warningCommonPassword]: 'Dit wachtwoord wordt veel gebruikt', | ||
[Feedback.warningDates]: 'Datums zijn vaak makkelijk te raden', | ||
[Feedback.warningDictionaryMatch]: 'Een enkel woord is makkelijk te raden', | ||
[Feedback.warningKeyboardPatterns]: 'Korte toetsenbord patronen zijn makkelijk te raden', | ||
[Feedback.warningRecentYears]: 'Recente jaartallen zijn makkelijk te raden', | ||
[Feedback.warningRepeatsAAA]: 'Herhalingen zoals \'aaa\' zijn makkelijk te raden', | ||
[Feedback.warningRepeatsAbc]: 'Herhalingen zoals \'abcabcabc\' zijn niet moeilijker te raden dan \'abc\', per se', | ||
[Feedback.warningRowsOfKeys]: 'Rechte lijnen van toetsen zijn makkelijk te raden', | ||
[Feedback.warningSequences]: 'Reeksen zoals \'abc\' en \'6543\' zijn makkelijk te raden', | ||
[Feedback.warningSimilarToCommonPassword]: 'Dit wachtwoord lijkt erg op een veelgebruikt wachtwoord', | ||
[Feedback.warningStandaloneName]: 'Opzichzelfstaande voor- en achternamen zijn makkelijk te raden', | ||
[Feedback.warningTop10Password]: 'Dit wachtwoord staat in de top-10 van veelvoorkomende wachtwoorden', | ||
[Feedback.warningTop100Password]: 'Dit wachtwoord staat in de top-100 van veelvoorkomende wachtwoorden', | ||
}; | ||
exports.dutchTranslations = (_a = {}, | ||
_a[Feedback.suggestionAddMoreWords] = 'Voeg nog een aantal woorden toe. Ongebruikelijke woorden zijn beter', | ||
_a[Feedback.suggestionAllUppercaseNoImprovement] = 'Wachtwoorden met enkel hoofdletters zijn niet veilig dan wachtwoorden met enkel kleine letters, per se', | ||
_a[Feedback.suggestionAvoidAssociatedDates] = 'Vermijd datums en jaartallen die met jou te maken hebben', | ||
_a[Feedback.suggestionAvoidAssociatedYears] = 'Vermijd jaartallen die met jou te maken hebben', | ||
_a[Feedback.suggestionAvoidRecentYears] = 'Vermijd recente jaartallen', | ||
_a[Feedback.suggestionAvoidRepeats] = 'Vermijd herhaalde woorden of tekens', | ||
_a[Feedback.suggestionAvoidSequences] = 'Vermijd reeksen van tekens', | ||
_a[Feedback.suggestionIncreaseKeyboardPattern] = 'Gebruik een langer toetsenbord patroon met meerdere bochten', | ||
_a[Feedback.suggestionIncreaseWords] = 'Gebruik een aantal woorden, vermijd bekende termen', | ||
_a[Feedback.suggestionPredictableSubstitutions] = 'Voorspelbare vervangers, zoals \'@\' voor een \'a\', helpen niet echt', | ||
_a[Feedback.suggestionReversedWords] = 'Omgekeerde woorden zijn niet moeilijker te raden, per se', | ||
_a[Feedback.suggestionUnnecessaryCapitalization] = 'Hoofdlettergebruik helpt niet echt', | ||
_a[Feedback.suggestionUnnecessaryCharacters] = 'Symbolen, nummers of hoofdletters zijn niet nodig, per se', | ||
_a[Feedback.warningCommonName] = 'Veelvoorkomende voor- en achternamen zijn makkelijk te raden', | ||
_a[Feedback.warningCommonPassword] = 'Dit wachtwoord wordt veel gebruikt', | ||
_a[Feedback.warningDates] = 'Datums zijn vaak makkelijk te raden', | ||
_a[Feedback.warningDictionaryMatch] = 'Een enkel woord is makkelijk te raden', | ||
_a[Feedback.warningKeyboardPatterns] = 'Korte toetsenbord patronen zijn makkelijk te raden', | ||
_a[Feedback.warningRecentYears] = 'Recente jaartallen zijn makkelijk te raden', | ||
_a[Feedback.warningRepeatsAAA] = 'Herhalingen zoals \'aaa\' zijn makkelijk te raden', | ||
_a[Feedback.warningRepeatsAbc] = 'Herhalingen zoals \'abcabcabc\' zijn niet moeilijker te raden dan \'abc\', per se', | ||
_a[Feedback.warningRowsOfKeys] = 'Rechte lijnen van toetsen zijn makkelijk te raden', | ||
_a[Feedback.warningSequences] = 'Reeksen zoals \'abc\' en \'6543\' zijn makkelijk te raden', | ||
_a[Feedback.warningSimilarToCommonPassword] = 'Dit wachtwoord lijkt erg op een veelgebruikt wachtwoord', | ||
_a[Feedback.warningStandaloneName] = 'Opzichzelfstaande voor- en achternamen zijn makkelijk te raden', | ||
_a[Feedback.warningTop10Password] = 'Dit wachtwoord staat in de top-10 van veelvoorkomende wachtwoorden', | ||
_a[Feedback.warningTop100Password] = 'Dit wachtwoord staat in de top-100 van veelvoorkomende wachtwoorden', | ||
_a); |
@@ -1,16 +0,48 @@ | ||
import React, { forwardRef, useState, } from 'react'; | ||
import { PasswordInput } from '..'; | ||
import { getStrength, getSuggestions, getWarning } from './helpers'; | ||
import { SecurePasswordFeedback, SecurePasswordMeter } from './subcomponents'; | ||
import './SecurePasswordInput.css'; | ||
const SecurePasswordInput = forwardRef(({ minimumLength = 8, minimumScore = 2, adviceLinkText, adviceLinkURL, onChange, className = '', ...inputProps }, ref) => { | ||
const [password, setPassword] = useState(); | ||
const [strength, setStrength] = useState(0); | ||
const [warning, setWarning] = useState(); | ||
const [suggestions, setSuggestions] = useState(); | ||
const handleChange = (value) => { | ||
const passwordStrength = getStrength(value); | ||
const passwordWarning = getWarning(value); | ||
const passwordSuggestions = getSuggestions(value); | ||
const passwordIsValid = value.length >= minimumLength && passwordStrength >= minimumScore; | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importStar(require("react")); | ||
var __1 = require(".."); | ||
var helpers_1 = require("./helpers"); | ||
var subcomponents_1 = require("./subcomponents"); | ||
require("./SecurePasswordInput.css"); | ||
var SecurePasswordInput = react_1.forwardRef(function (_a, ref) { | ||
var _b = _a.minimumLength, minimumLength = _b === void 0 ? 8 : _b, _c = _a.minimumScore, minimumScore = _c === void 0 ? 2 : _c, adviceLinkText = _a.adviceLinkText, adviceLinkURL = _a.adviceLinkURL, onChange = _a.onChange, _d = _a.className, className = _d === void 0 ? '' : _d, inputProps = __rest(_a, ["minimumLength", "minimumScore", "adviceLinkText", "adviceLinkURL", "onChange", "className"]); | ||
var _e = react_1.useState(), password = _e[0], setPassword = _e[1]; | ||
var _f = react_1.useState(0), strength = _f[0], setStrength = _f[1]; | ||
var _g = react_1.useState(), warning = _g[0], setWarning = _g[1]; | ||
var _h = react_1.useState(), suggestions = _h[0], setSuggestions = _h[1]; | ||
var handleChange = function (value) { | ||
var passwordStrength = helpers_1.getStrength(value); | ||
var passwordWarning = helpers_1.getWarning(value); | ||
var passwordSuggestions = helpers_1.getSuggestions(value); | ||
var passwordIsValid = value.length >= minimumLength && passwordStrength >= minimumScore; | ||
setPassword(value); | ||
@@ -22,8 +54,8 @@ setStrength(passwordStrength); | ||
}; | ||
return (React.createElement("div", { className: `spi ${className}` }, | ||
React.createElement(PasswordInput, Object.assign({}, inputProps, { ref: ref, minLength: minimumLength, onChange: handleChange })), | ||
adviceLinkText && adviceLinkURL && (React.createElement("a", { href: adviceLinkURL, target: "_blank", rel: "noopener noreferrer", className: "spi__advice-link custom-spi__advice-link" }, adviceLinkText)), | ||
password && React.createElement(SecurePasswordMeter, { strength: strength }), | ||
password && React.createElement(SecurePasswordFeedback, { warning: warning, suggestions: suggestions }))); | ||
return (react_1.default.createElement("div", { className: "spi " + className }, | ||
react_1.default.createElement(__1.PasswordInput, __assign({}, inputProps, { ref: ref, minLength: minimumLength, onChange: handleChange })), | ||
adviceLinkText && adviceLinkURL && (react_1.default.createElement("a", { href: adviceLinkURL, target: "_blank", rel: "noopener noreferrer", className: "spi__advice-link custom-spi__advice-link" }, adviceLinkText)), | ||
password && react_1.default.createElement(subcomponents_1.SecurePasswordMeter, { strength: strength }), | ||
password && react_1.default.createElement(subcomponents_1.SecurePasswordFeedback, { warning: warning, suggestions: suggestions }))); | ||
}); | ||
export default SecurePasswordInput; | ||
exports.default = SecurePasswordInput; |
@@ -1,3 +0,9 @@ | ||
import SecurePasswordFeedback from './SecurePasswordFeedback'; | ||
import SecurePasswordMeter from './SecurePasswordMeter'; | ||
export { SecurePasswordFeedback, SecurePasswordMeter, }; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var SecurePasswordFeedback_1 = __importDefault(require("./SecurePasswordFeedback")); | ||
exports.SecurePasswordFeedback = SecurePasswordFeedback_1.default; | ||
var SecurePasswordMeter_1 = __importDefault(require("./SecurePasswordMeter")); | ||
exports.SecurePasswordMeter = SecurePasswordMeter_1.default; |
@@ -1,6 +0,14 @@ | ||
import React from 'react'; | ||
const SecurePasswordFeedback = ({ warning, suggestions }) => (React.createElement("div", null, | ||
warning && (React.createElement("p", { className: "custom-spi__warning" }, | ||
React.createElement("strong", null, warning))), | ||
suggestions && (React.createElement("ul", { className: "custom-spi__suggestion-list" }, suggestions.map(suggestion => (React.createElement("li", { key: suggestion, className: "custom-spi__suggestion" }, suggestion))))))); | ||
export default SecurePasswordFeedback; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importDefault(require("react")); | ||
var SecurePasswordFeedback = function (_a) { | ||
var warning = _a.warning, suggestions = _a.suggestions; | ||
return (react_1.default.createElement("div", null, | ||
warning && (react_1.default.createElement("p", { className: "custom-spi__warning" }, | ||
react_1.default.createElement("strong", null, warning))), | ||
suggestions && (react_1.default.createElement("ul", { className: "custom-spi__suggestion-list" }, suggestions.map(function (suggestion) { return (react_1.default.createElement("li", { key: suggestion, className: "custom-spi__suggestion" }, suggestion)); }))))); | ||
}; | ||
exports.default = SecurePasswordFeedback; |
@@ -1,9 +0,15 @@ | ||
import React from 'react'; | ||
import { getStrengthFeedback } from '../helpers'; | ||
const SecurePasswordMeter = ({ strength }) => { | ||
const strengthFeedback = getStrengthFeedback(strength); | ||
return (React.createElement(React.Fragment, null, | ||
React.createElement("p", { className: "custom-spi__strength-label" }, strengthFeedback), | ||
React.createElement("meter", { min: 0, max: 4, value: strength, className: "spi__strength-meter custom-spi__strength-meter" }))); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
export default SecurePasswordMeter; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importDefault(require("react")); | ||
var helpers_1 = require("../helpers"); | ||
var SecurePasswordMeter = function (_a) { | ||
var strength = _a.strength; | ||
var strengthFeedback = helpers_1.getStrengthFeedback(strength); | ||
return (react_1.default.createElement(react_1.default.Fragment, null, | ||
react_1.default.createElement("p", { className: "custom-spi__strength-label" }, strengthFeedback), | ||
react_1.default.createElement("meter", { min: 0, max: 4, value: strength, className: "spi__strength-meter custom-spi__strength-meter" }))); | ||
}; | ||
exports.default = SecurePasswordMeter; |
@@ -1,2 +0,4 @@ | ||
import { SecurePasswordInput } from './compositions'; | ||
export default SecurePasswordInput; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var compositions_1 = require("./compositions"); | ||
exports.default = compositions_1.SecurePasswordInput; |
{ | ||
"name": "@createnl/secure-password-input", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "A password input that provides user with rating and advice on how secure their password is, based on ZXCVBN", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -16,3 +16,3 @@ { | ||
], | ||
"module": "esnext", | ||
"module": "CommonJS", | ||
"moduleResolution": "node", | ||
@@ -32,3 +32,3 @@ "noEmit": false, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"target": "esnext" | ||
"target": "es5" | ||
}, | ||
@@ -35,0 +35,0 @@ "include": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94135
77
1922