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 ioutils单元3查找并搜索文件夹信息

Delphi utf8乱码问题

Delphi 跨平台打开网址链接

Delphi 读写文本文件

Delphi firemonkey限制tedit只能输入数字的完美方法

Delphi 时间转换为gmt格式

Delphi取得trichedit的光标当前位置

Delphi根据网络链接截取域名

Delphi 类的声明

Delphi 完美的线程注入和卸载

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



打赏

取消

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

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

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

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

评论

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