Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to generate random password string Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
04-Jun-03
Category
Algorithm
Language
Delphi 2.x
Views
135
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Mike Shkolnik

How can I generate the random password in own program?

Answer:

Solve 1:

In last holidays I wrote a small dialog for random password generation. It's a 
simple but results is very useful:)) 

Try it: 
1   
2   function TfrmPWGenerate.btnGenerateClick(Sender: TObject): string;
3   
4   {max length of generated password}
5   const
6     intMAX_PW_LEN = 10;
7   var
8     i: Byte;
9     s: string;
10  begin
11    {if you want to use the 'A..Z' characters}
12    if cbAZ.Checked then
13      s := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
14    else
15      s := '';
16  
17    {if you want to use the 'a..z' characters}
18    if cbAZSmall.Checked then
19      s := s + 'abcdefghijklmnopqrstuvwxyz';
20  
21    {if you want to use the '0..9' characters}
22    if cb09.Checked then
23      s := s + '0123456789';
24    if s = '' then
25      exit;
26  
27    Result := '';
28    for i := 0 to intMAX_PW_LEN - 1 do
29      Result := Result + s[Random(Length(s) - 1) + 1];
30  end;
31  
32  initialization
33    Randomize;


The sample results: 

IBbfA1mVK2 
tmuXIuQJV5 
oNEY1cF6xB 
flIUhfdIui 
mxaK71dJaq 
B0YTqxdaLh 
... 

I think that it's no bad:)) Of course, you can add the some additional crypt 
methods and check of unique. 


Solve 2:

f
34  unction GenPassWord(): string;
35  var
36    nCounter: integer;
37    cString: string;
38    cNumber: integer;
39  begin
40    Randomize;
41    cString := '';
42    // nCounter = password length
43    for nCounter := 0 to 8 do
44    begin
45      repeat
46        cNumber := Random(122);
47        // for capitol chrs extend the range
48      until (nNumber >= 97) and (nNumber <= 122);
49      cString := cString + Chr(nNumber);
50    end;
51    Result := cString;
52  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC