Code Monkey home page Code Monkey logo

antd-password-input-strength's Introduction

npm GitHub issues GitHub license Twitter Greenkeeper badge

antd-password-input-strength

Antd Input Component with password-strength indicator.

Preview GIF

Features

  • Drop-in replacement for antd's Input component
  • Customizable
  • Uses tai-password-strength for password strength estimation

Note: tai-password-strength is a rather large library. Use code splitting to only load the library when necessary.

Install

npm install --save antd-password-input-strength

or

yarn add --save antd-password-input-strength

Note: antd and react/react-dom are peer dependencies. You should only use this library in a React/AntD project.

Usage

Use as a drop-in replacement for antd's Input:

<Form>
    <Form.Item label="Password">
        <PasswordInput />
    </Form.Item>
</Form>

With Form.create():

<Form>
    <Form.Item label="Password">
    {this.props.form.getFieldDecorator("password", {
        rules: [{
            required: true,
            message: "Please enter your password"
        }]
    })(<PasswordInput />)}
    </Form.Item>
</Form>

With custom settings:

<Form>
    <Form.Item label="Password">
        <PasswordInput 
            settings={{
                ...defaultSettings,
                height: 5
            }}
            
            onChange={() => console.log("Changed")}
            size="large"
        />
    </Form.Item>
</Form>

With validation:

function ValidationExample() {
  const [level, setLevel] = useState(0)

  const minLevel = 1;
  const errorMessage = 'Password is too weak';

  return (
    <Form>
      <Form.Item
        name="test"
        rules={[{
          validator: async () => {
            return level >= minLevel ? Promise.resolve() : Promise.reject(errorMessage);
          },
          message: errorMessage
        }]}
      >
        <PasswordInput onLevelChange={setLevel} />
      </Form.Item>
    </Form>
  );
}

API

PasswordInput

props type description
settings PasswordInputSettings Strength indicator display settings
onLevelChange (newLevel: 0 1
...props InputProps Pass additional properties to the underlying Input component

PasswordInputSettings

props type description
colorScheme ColorScheme Modify the indicator's color scheme
height number Change indicator bar height (in px)
alwaysVisible boolean If false, the bar only appears if the input field isn't empty

Default:

{
    colorScheme: [...],
    height: 3,
    alwaysVisible: false
}

ColorScheme

props type description
levels string[] Array of CSS color codes for the different strength levels:
levels[0] = weakest, levels[4] = strongest
noLevel string CSS color code for non-colored strength indicator bars.

Default:

{
    levels: ["#ff4033", "#fe940d", "#ffd908", "#cbe11d", "#6ecc3a"],
    noLevel: "lightgrey"
}

License

MIT

antd-password-input-strength's People

Contributors

cheickmec avatar greenkeeper[bot] avatar kombustor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

antd-password-input-strength's Issues

An in-range update of antd is breaking the build 🚨

The devDependency antd was updated from 3.14.1 to 3.15.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

antd is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: install: Your tests passed on CircleCI! (Details).
  • ci/circleci: lint: CircleCI is running your tests (Details).
  • ci/circleci: build: Your tests passed on CircleCI! (Details).
  • ci/circleci: test: Your tests failed on CircleCI (Details).

Release Notes for 3.15.0
  • 🌟 Tree supports new prop blockNode. #14858 @kimochg
  • Form
  • 🐞 Fix Typography dom structure. #15210
  • 🐞 Fix Affix position update logic. #15150
  • Input
    • 🐞 Fix Password lost focus when change visibilityToggle. #15184
    • 🐞 Fix allowClear do not focus after clear content. #15184
    • 🐞 Fix Search style with allowClear or suffix/prefix. #15242
    • 🐞 Fix Input warning logic for focus lose. #15251
  • 🐞 Fix DatePicker and TimePicker cursor style. #15218 @yoyo837
  • 🐞 Fix Steps label text not align center. #15256
  • TypeScript
    • ⚡️ Refactor and simplify List Item dom structure, and fix spaces lost inside List Item. #15197
    • 🐞 Fix Layout tagName definition. #15181 @ngolin
    • 🐞 Fix Text ellipsis definition. #15209 @xiaohuoni
    • 🐞 Fix Badge text types. #15264
  • 🇹🇷 Turkish translations of new components. #15238 @codesignist

  • 🌟 Tree 组件支持 blockNode 属性。#14858 @kimochg
  • Form
  • ⚡️ 重构并简化了 List Item 的 dom 结构,并且修复了 Item 中内容空格丢失的问题。#15210
  • 🐞 修复 Affix 组件定位更新的逻辑问题。#15150
  • Input
    • 🐞 修复 Password 当 visibilityToggle 变化时丢失焦点的问题。#15184
    • 🐞 修复通过 allowClear 清除内容后没有获得焦点的问题。#15184
    • 🐞 修复 Search 当使用了 allowClear 或者 suffix/prefix 时的样式问题。#15242
    • 🐞 修复 Input 丢失焦点时的警告问题。#15251
  • 🐞 修复 DatePicker 和 TimePicker 的 cursor 样式问题。#15218 @yoyo837
  • 🐞 修复 Steps 的 label 不居中的问题。#15256
  • TypeScript
    • 🐞 修复 Typography 的 setContentRef 定义。#15197
    • 🐞 修复 Layout 的 tagName 定义。#15181 @ngolin
    • 🐞 修复 Text 的 ellipsis 定义。#15209 @xiaohuoni
    • 🐞 修复 Badge 的 text 定义。#15264
  • 🇹🇷 添加一些新组件的土耳其语翻译。#15238 @codesignist
Commits

The new version differs by 99 commits.

  • f2b95d0 chore: add changelog for 3.15.0 (#15281)
  • a79c788 Merge pull request #15282 from ant-design/feature
  • b807859 Merge branch 'master' into feature
  • 8f8471f :lipstick: fix missing semicolon
  • 4cb2850 Merge pull request #15283 from ant-design/chore/mergem
  • e3a2c38 Merge branch 'master' into chore/mergem
  • 194dedd Merge pull request #15286 from ant-design/improve-code
  • 884e135 Merge pull request #15285 from jinxin0112/patch-1
  • bd0eb34 make sure count compare as number
  • 71440a2 Update components/form/style/index.less
  • da66625 :zap: refactor some code after #15254
  • 7ccf685 fix: appear two colons
  • a4f73ff chore: sync master to feature
  • d02ec78 Merge pull request #15276 from DiamondYuan/form-prop
  • 120ea3a Merge pull request #15252 from yoyo837/add-label-align

There are 99 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Prevent sending unsecure passwords on submit

Problem
There is no option to validate the form with the password strength at the moment. So for displaying how strong the password is it seems great. But there seems no way to prevent the user from sending insecure passwords. Or am I missing something?

Solution
A property for props like validation=true || false which toggles the validation of the password and prevents it from sending if unsecure.

Placeholder missing

Hey man, this is wonderful, thank you! But how do you pass a placeholder? I tried and it doesn't show up

Always throws an error if the password is pasted into the input box

Describe the bug
Throws an error when the password is pasted instead of typed.

To Reproduce

  1. I used this example from the docs:
    image
  2. Type a password which is accepted by the component without error. Copy that and paste it back.
  3. You will see an error "Password is too weak"

Expected behavior

  • I think it should work right on paste as well.

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser : Chrome

Fix I will be using in my project for now

  • level changes only after the validator function has started
import { useEffect, useState } from "react";
import "./styles.css";
import { Form } from "antd";
import { PasswordInput } from "antd-password-input-strength";

export default function App() {
  const [level, setLevel] = useState(0);
  const [form] = Form.useForm();

  const minLevel = 1;
  const errorMessage = "Password is too weak";

  useEffect(() => {
    form.validateFields();
  }, [level, form]);

  return (
    <Form form={form}>
      <Form.Item
        name="test"
        rules={[
          {
            validator: async () => {
              return level >= minLevel
                ? Promise.resolve()
                : Promise.reject(errorMessage);
            },
            message: errorMessage
          }
        ]}
      >
        <PasswordInput onLevelChange={setLevel} />
      </Form.Item>
    </Form>
  );
}

Inconsistent password strength with tai

Describe the bug
The demo page calculates a different strength from the one the input displays.

To Reproduce
Steps to reproduce the behavior:

  1. Try andt password input strength input with the password 9(8*7&aBc
  2. Try the same password in the demo page.
  3. Demo page returns with:
    { charsetSize: 94, commonPassword: false, passwordLength: 9, shannonEntropyBits: 28.52932501298081, strengthCode: 'REASONABLE', trigraphEntropyBits: 58.237911691530336, number: true, lower: true, upper: true, punctuation: true, symbol: true }

Which is a reasonably strong password, but the Password input component considers it VERY_WEAK.

Expected behavior
The statuses should match

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome
  • Version: 102

An in-range update of antd is breaking the build 🚨

The devDependency antd was updated from 3.20.4 to 3.20.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

antd is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: install: Your tests passed on CircleCI! (Details).
  • ci/circleci: build: Your tests passed on CircleCI! (Details).
  • ci/circleci: lint: Your tests passed on CircleCI! (Details).
  • ci/circleci: test: Your tests failed on CircleCI (Details).

Release Notes for 3.20.5
  • 🐞 Fix <Button type="danger" ghost /> broken style. #17743

  • 🐞 修复 <Button type="danger" ghost /> 样式问题。#17743
Commits

The new version differs by 5 commits.

  • bf2abd1 :sparkles: 3.20.5
  • 896e4e8 Merge pull request #17743 from ant-design/fix-danger-ghost-button
  • 3f2e1b1 Merge pull request #17708 from cottom/chore/remove-extra-disabled
  • 3c771b3 :bug: Fix Button danger style when type is ghost
  • 77d8c92 chore: remove unnecessary disable default props

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Error unique "key" prop

  • This is the error when I used the PasswordInput
  • Also maybe you may use the new version input for password Input.Password
  • It's possible to add a validator as a minimum strength?

index.js:2178 Warning: Each child in an array or iterator should have a unique "key" prop.

Check the top-level render call using

. See https://fb.me/react-warning-keys for more information.
in div
in Unknown (created by PasswordInput)
in div (created by PasswordInput)
in PasswordInput (at Password.js:18)
in span (created by Context.Consumer)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.