import { Form, Progress } from "antd"; import React from "react"; import "./index.less"; //CharMode函数 //测试某个字符是属于哪一类. const CharMode = (iN: number) => { if (iN >= 48 && iN <= 57) //数字 return 1; if (iN >= 65 && iN <= 90) //大写字母 return 2; if (iN >= 97 && iN <= 122) //小写 return 4; else return 8; //特殊字符 }; const getPwdStrength = (pwd: string): number => { let level = 1; pwd = pwd.trim(); if (pwd) { let typeNumer: number[] = []; for (let index = 0; index < pwd.length; index++) { const numer = CharMode(pwd.charCodeAt(index)); if (!typeNumer.includes(numer)) { typeNumer.push(numer); } } level = typeNumer.length; } return level; }; const list = [ { name: "弱", color: "#e74242", }, // { // name: "弱", // color: "#EFBD47", // }, { name: "一般", color: "#ffa500", }, { name: "强", color: "#1bbf1b", }, { name: "非常强", color: "#4096ff", }, ]; interface Props { password: string; } const watchStrength = (password: string): number => { const level = getPwdStrength(password); const num = Math.floor((level / list.length) * 100); return num; }; export default function CheckPassword(props: Props) { const { password = "" } = props; return ( <div className="pwd-progress"> <Progress percent={password ? watchStrength(password) : 0} steps={list.length} strokeColor={list.map((f) => f.color)} showInfo={false} /> <div className="info"> {list.map((item) => { return <div key={item.name}>{item.name}</div>; })} </div> </div> ); }
正文
js密码强度效验
文章版权声明:除非注明,否则均为
譬如朝露_策温技术开发工作室博客原创文章,转载或复制请以超链接形式并注明出处。
发表评论
侧栏公告
寄语
譬如朝露博客是一个分享前端知识的网站,联系方式11523518。
热评文章
标签列表
热门文章
友情链接