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 getforegroundwindow 与 getactivewindow 的区别

Delphi 在rxrichedit中插入图片的完美解决方法

Delphi中如何将一整个文件读入内存

winapi 字符及字符串函数(5): ischaralpha - 是否是个字母

Delphi下idhttp配合cookiemanager获取cookie

实现拖动无标题窗口的5种方法

Delphi 2009 indy10 idhttp get 中文出现乱码的问题

Delphi+access错误"不正常地定义参数对象。提供了不一致或不完整的信息。"

Delphi 快速调用resource资源数据

最简单的Delphi驱动结束进程

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



打赏

取消

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

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

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

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

评论

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