Delphi 随机字符3


本文整理自网络,侵删。

 

function GeneratePassword(PasswordLength: Integer):string;
var
  SourceString: String;
  ExcludeString: String;
  RandomCharacter: String;
  RandomPassword: String;

  NumPassword: Integer;

begin
  Randomize;

  SourceString  := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789:!?''"()@';
  ExcludeString := '0O1lI|';

  if Length(SourceString) = 0 then exit;


  for NumPassword := 1 to 20 do
  begin
    RandomPassword := '';
    repeat

//    RandomCharacter := SourceString[Random(Length(SourceString)) + 1 ];
      RandomCharacter := SourceString.Substring(Random(Length(SourceString)),1);

//    if Pos( RandomCharacter, ExcludeString) = 0 then
    if ExcludeString.IndexOf(RandomCharacter) = -1 then
        RandomPassword := RandomPassword + RandomCharacter;
    until (Length(RandomPassword) = PasswordLength);

    result:= RandomPassword
  end;



end;

相关阅读 >>

Delphi wmi 获取操作系统信息

Delphi datetimetogmt gmt时间与tdatetime转换

Delphi 的编译指令(1): $define、$undef、$ifdef、$else、$endif

Delphi限制edit编辑框的输入

Delphi xe5 android listview

Delphi结构体的方法

Delphi 系统托盘组件 ttrayicon 简介

Delphi crc32算法

Delphi 判断操作系统是否是64位的函数

Delphi 映像劫持编辑器

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...