首页 > 其他分享 >Delphi 检测密码强度 规则(仿 google)

Delphi 检测密码强度 规则(仿 google)

时间:2023-05-11 11:22:44浏览次数:34  
标签:countUppercase countDigit google countLowercase Delphi else 密码 Result password

一、密码长度:

  • 5 分: 小于等于 4 个字符
  • 10 分: 5 到 7 字符
  • 25 分: 大于等于 8 个字符

二、字母:

  • 0 分: 没有字母
  • 10 分: 全都是小(大)写字母
  • 20 分: 大小写混合字母

三、数字:

  • 0 分: 没有数字
  • 10 分: 1 个数字
  • 20 分: 大于等于 3 个数字

四、符号:

  • 0 分: 没有符号
  • 10 分: 1 个符号
  • 25 分: 大于 1 个符号

五、奖励:

  • 2 分: 字母和数字
  • 3 分: 字母、数字和符号
  • 5 分: 大小写字母、数字和符号

最后的评分标准:

  • = 90: 非常安全
  • >= 80: 安全(Secure)
  • >= 70: 非常强
  • >= 60: 强(Strong)
  • >= 50: 一般(Average)
  • >= 25: 弱(Weak)
  • >= 0: 非常弱
function CheckPassword(password: string): Integer;  //检测密码强度  规则(仿 google)
var
  i, countLowercase, countUppercase, countDigit, countSymbol: Integer;
begin
  Result := 0;
  // 计算密码长度得分
  if Length(password) <= 4 then
    Result := 5
  else if (Length(password) >= 5) and (Length(password) <= 7) then
    Result := 10
  else if Length(password) >= 8 then
    Result := 25;
  // 计算字母得分
  countLowercase := 0;
  countUppercase := 0;
  for i := 1 to Length(password) do
  begin
    if password[i] in ['a'..'z'] then
      Inc(countLowercase)
    else if password[i] in ['A'..'Z'] then
      Inc(countUppercase);
  end;
  if (countLowercase = 0) and (countUppercase = 0) then
    Result := Result + 0
  else if (countLowercase > 0) and (countUppercase = 0) or (countLowercase = 0) and (countUppercase > 0) then
    Result := Result + 10
  else if (countLowercase > 0) and (countUppercase > 0) then
    Result := Result + 20;
  // 计算数字得分
  countDigit := 0;
  for i := 1 to Length(password) do
  begin
   if password[i] in ['0'..'9'] then
      Inc(countDigit);
  end;
  if countDigit = 0 then
    Result := Result + 0
  else if countDigit = 1 then
    Result := Result + 10
  else if countDigit >= 3 then
    Result := Result + 20;
  // 计算符号得分
  countSymbol := 0;
  for i := 1 to Length(password) do
  begin
    if not (password[i] in ['a'..'z', 'A'..'Z', '0'..'9']) then
      Inc(countSymbol);
  end;
  if countSymbol = 0 then
    Result := Result + 0
  else if countSymbol = 1 then
    Result := Result + 10
  else if countSymbol > 1 then
    Result := Result + 25;
  // 计算奖励得分
  if (countLowercase > 0) and (countUppercase > 0) and (countDigit > 0) and (countSymbol = 0) then
    Result := Result + 2
  else if (countLowercase > 0) and (countUppercase > 0) and (countDigit > 0) and (countSymbol > 0) then
    Result := Result + 3
  else if (countLowercase > 0) and (countUppercase > 0) and (countDigit > 0) and (countSymbol > 0) then
    Result := Result + 5;
end;

function CheckPasswordw(score: Integer):String;
begin
    // 计算最终得分
  if score >= 90 then
    Result := '非常安全'
  else if score >= 80 then
    Result := '安全(Secure)'
  else if score >= 70 then
    Result := '非常强'
  else if score >= 60 then
    Result := '强(Strong)'
  else if score >= 50 then
    Result := '一般(Average)'
  else if score >= 25 then
    Result := '弱(Weak)'
  else
    Result := '非常弱'; // 密码非常弱
end;

procedure TForm1.Button1Click(Sender: TObject);  //检测
begin
   Edit2.Text:=IntToStr(CheckPassword(Edit1.Text));
   Edit3.Text:=CheckPasswordw(StrToInt(Edit2.Text));
end;

 

标签:countUppercase,countDigit,google,countLowercase,Delphi,else,密码,Result,password
From: https://www.cnblogs.com/WilliamLv/p/17390506.html

相关文章

  • delphi 遍历枚举、获取枚举值的名称
    遍历枚举、获取枚举值的名称代码遍历枚举usesSystem.TypInfo;procedureTForm1.Button1Click(Sender:TObject);varI:TAlign;beginforI:=Low(TAlign)toHigh(TAlign)dobeginMemo1.Lines.Add('名称'+GetEnumName(TypeInfo(TAlign),Ord(I))+'值......
  • BBS首页的搭建之导航条and修改密码功能的实现
    目录一、导航条的搭建html页面二、修改密码功能的实现html页面搭建修改密码后端逻辑实现1.session登录装饰器的验证2.阻止事件二次提交,主要针对bottom按钮在form表单中,又绑定了Ajax提交:3.视图函数功能逻辑的实现4.js前端页面的实现三、退出登录功能的实现1.视图函数一、导航条的......
  • 2023移动光猫H2-2超级密码获取教程
    记录信息普通账户登录光猫后台,记录下宽带的账密、loid。如果后台查询不到以上信息,则可以按照如下办法获得宽带的账密不知道,也可以登录移动APP去查询和重置。loid不知道,则联系10086安排维修,然后联系其师傅电话咨询即可,不要问10086客服,她们不懂。这个用于光猫注册用的,注册后......
  • ubuntu 云镜像默认密码重置
    ubuntu云镜像默认密码重置背景ubuntu的云镜像,默认是没有提供用户名密码的,当我们直接启动时,就无法登陆进去,真的是难受坏了。解决办法通过重置root密码来设置一个初始化密码即可例子以ubuntu22.04版本为例①下载地址:https://cloud-images.ubuntu.com/jammy/current/②创......
  • delphi执行外部程序并等待结束返回响应
    //写成函数需要引用ShellAPI单元;functionExecuteFileWait(ExecuteFile:string):Integer;//实现执行外部程序,并等待程序结束的函数,返回值为1varSEInfo:TShellExecuteInfo;ExitCode:DWORD;ParamString,StartInString:string;beginFillChar(SEInfo,S......
  • vCenter的root密码过期修改
    登录vCenter的5480端口,报错“ExceptionininvokingauthenticationhandlerUserpasswordexpired”,提示root密码过期 解决办法:1、重启vCenter,启动后按e进入GRUB菜单,在linux那行结尾添加“rwinit=/bin/bash” 2、然后按F10继续加载,显示如下: 3、命令行输入passwd重置r......
  • Python 密码破解指南:15~19
    协议:CCBY-NC-SA4.0译者:飞龙本文来自【OpenDocCN饱和式翻译计划】,采用译后编辑(MTPE)流程来尽可能提升效率。收割SB的人会被SB们封神,试图唤醒SB的人是SB眼中的SB。——SB第三定律十五、破解仿射密码原文:https://inventwithpython.com/cracking/chapter15.html......
  • Python 密码破解指南:0~4
    协议:CCBY-NC-SA4.0译者:飞龙本文来自【OpenDocCN饱和式翻译计划】,采用译后编辑(MTPE)流程来尽可能提升效率。收割SB的人会被SB们封神,试图唤醒SB的人是SB眼中的SB。——SB第三定律零、简介原文:https://inventwithpython.com/cracking/chapter0.html“我是无意......
  • Google Chrome浏览器离线安装包下载方式
    GoogleChrome是应用很广泛的浏览器,默认是在线安装模式。如果网络速度很慢,或者没有网络的时候,就需要离线安装包了。32位Chrome离线包下载:http://www.google.cn/chrome/browser/desktop/index.html?standalone=164位Chrome离线包下载:http://www.google.cn/chrome/brow......
  • 密码工程-扩展欧几里得算法
    任务详情0.在openEuler(推荐)或Ubuntu或Windows(不推荐)中完成下面任务1.参考《密码工程》p112伪代码实现ExtendedGCD(inta,intb,int*k,int*u,int*v)算法(52.在测试代码中计算74模167的逆。(53.自己设计至少两个测试代码。54.提交代码和运行结果截图代码实现......