如何创建一个随机的密码

dregs 2002-02-19 05:17:45
如何创建一个随机的密码
...全文
20 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
torble 2002-02-19
  • 打赏
  • 举报
回复
var
word:string;
pass:string;
I:integer;
begin
Randomize;
word:='abcdefghijklmnopqrstuvwxyz';
pass:='';
for i:=0 to 8 do
pass:=pass+copy(word,trunc(length(word)*random+1),1);
edit1.text:=pass;
end;
kuangning 2002-02-19
  • 打赏
  • 举报
回复
用DES算吧,取当前时间、本机ip等数据作为密匙和原文进行加密后,取密文的16进制就行了
dregs2002 2002-02-19
  • 打赏
  • 举报
回复
// call Randomize only once at application start.
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
end;

function RandomPwd(PWLen: integer): string;
// set the Table of chars to used in Passwords
const StrTable: string =
'!#$%&/()=?@<>|{[]}\*~+#;:.-_' +
'ABCDEFGHIJKLMabcdefghijklm' +
'0123456789' +
'闹茕鳇? +
'NOPQRSTUVWXYZnopqrstuvwxyz';
var
N, K, X, Y: integer;
begin
// check the maximum of Password-length
if (PWlen > Length(StrTable)) then K := Length(StrTable)-1
else K := PWLen;
SetLength(result, K); // set result-string-length
Y := Length(StrTable); // Table length for inner loop
N := 0; // loop start value

while N < K do begin // loop to create K chars
X := Random(Y) + 1; // get next random char
// check the presence of this char in the result-string
if (pos(StrTable[X], result) = 0) then begin
inc(N); // it's not found
Result[N] := StrTable[X]; // store it now
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
cPwd: string;
begin
// e.g. create a random-Password with 30 chars
cPwd := RandomPwd(30);
// ...
end;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧