Forum > Other

Password Generator XE

(1/4) > >>

Hi, all

I made a new little project it just a handy program to create secure random passwords using different characters anyway have a look at the website, there you find a Windows portable app and the source code.

Tony Stone:
Just downloaded it and compiled it to run on Linux.  I am having a difficult time viewing your user interface because you changed the forms default colors.  But either way I see how it works.  I have actually made a similar password generator a couple years ago and just re-visited it recently and started "improving" it.  I don't think it matters very much because it is not like you have millions of people using it but I wouldn't consider the Random function to be "secure".  I know with the little bit of cryptographic programming I have done I found that the Random function is far from random.  If you want to work in a really secure random number generator have a look at secure random function of the CryptoLib4Pascal.  I am currently looking at ways to use it for my password generator!  :D

Without watching how you guys done, here is my contribution to such topic:
(Appended is a demo project that uses most features)

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit kz.Password; (* ************************** *)(*                            *)(*  TkzPassword by KodeZwerg  *)(*                            *)(*  Type: Password Generator  *)(*  License: The Unlicense    *)(*                            *)(* ************************** *)  {$mode ObjFPC}{$H+} interface uses  Classes, SysUtils; type  TAnsiChars = array of AnsiChar;  TModeSelector = (msBits, msChars);  TPasswordEvent = procedure(Sender: TObject; const APassword: AnsiString) of object;   { TkzPassword }   TkzPassword = class(TPersistent)    strict private      FNumbers: TAnsiChars;      FLettersHi: TAnsiChars;      FLettersLo: TAnsiChars;      FSpecials: TAnsiChars;      FCustom: TAnsiChars;      FUseNumbers: Boolean;      FUseLettersHi: Boolean;      FUseLettersLo: Boolean;      FUseSpecials: Boolean;      FUseCustom: Boolean;      FModeSelection: TModeSelector;      FCount: Integer;      FPassword: AnsiString;      FPasswordEvent: TPasswordEvent;    private      function BitsToChars(const ABits: Integer): Integer;      procedure AddCharacter(var AArray: TAnsiChars; const AChar: AnsiChar);      procedure GenerateNumbers;      procedure GenerateLettersHi;      procedure GenerateLettersLo;      procedure GenerateSpecials;      procedure CreateArrays;      procedure ClearArrays;    public      constructor Create;      destructor Destroy; override;      procedure AddCustom(const AChar: AnsiChar);      procedure Generate;    published      property UseNumbers: Boolean read FUseNumbers write FUseNumbers default True;      property UseLettersHi: Boolean read FUseLettersHi write FUseLettersHi default True;      property UseLettersLo: Boolean read FUseLettersLo write FUseLettersLo default True;      property UseSpecials: Boolean read FUseSpecials write FUseSpecials default True;      property UseCustom: Boolean read FUseCustom write FUseCustom default False;      property Count: Integer read FCount write FCount default -1;      property Mode: TModeSelector read FModeSelection write FModeSelection default msBits;      property Password: AnsiString read FPassword;      property OnGenerate: TPasswordEvent read FPasswordEvent write FPasswordEvent;  end;  implementation { TPassword } constructor TkzPassword.Create;begin  Randomize;  CreateArrays;  FPassword      := '';  FPasswordEvent := nil;  FUseNumbers    := True;  FUseLettersHi  := True;  FUseLettersLo  := True;  FUseSpecials   := True;  FUseCustom     := False;  FModeSelection := msBits;  FCount := -1;end; destructor TkzPassword.Destroy;begin  ClearArrays;  FPassword := '';  FPasswordEvent := nil;end; function TkzPassword.BitsToChars(const ABits: Integer): Integer;begin  if (ABits mod 8 = 0) then    Result := ABits div 8  else    Result := -1;end; procedure TkzPassword.AddCharacter(var AArray: TAnsiChars; const AChar: AnsiChar);var  i: Integer;begin  i := Length(AArray);  SetLength(AArray, Succ(i));  AArray[i] := AChar;end; procedure TkzPassword.AddCustom(const AChar: AnsiChar);begin  AddCharacter(FCustom, AChar);end; procedure TkzPassword.GenerateNumbers;var  i: Integer;begin  for i := 0 to 9 do    AddCharacter(FNumbers, AnsiChar(IntToStr(i)[1]));end; procedure TkzPassword.GenerateLettersHi;var  i: Integer;begin  for i := 0 to 25 do    AddCharacter(FLettersHi, Chr(Ord('A') + i));end; procedure TkzPassword.GenerateLettersLo;var  i: Integer;begin  for i := 0 to 25 do    AddCharacter(FLettersLo, Chr(Ord('a') + i));end; procedure TkzPassword.GenerateSpecials;begin  AddCharacter(FSpecials, AnsiChar('!'));  AddCharacter(FSpecials, AnsiChar('"'));//  AddCharacter(FSpecials, AnsiChar('§'));  AddCharacter(FSpecials, AnsiChar('$'));  AddCharacter(FSpecials, AnsiChar('%'));  AddCharacter(FSpecials, AnsiChar('&'));  AddCharacter(FSpecials, AnsiChar('/'));  AddCharacter(FSpecials, AnsiChar('('));  AddCharacter(FSpecials, AnsiChar(')'));  AddCharacter(FSpecials, AnsiChar('='));  AddCharacter(FSpecials, AnsiChar('?'));//  AddCharacter(FSpecials, AnsiChar('²'));//  AddCharacter(FSpecials, AnsiChar('³'));  AddCharacter(FSpecials, AnsiChar('{'));  AddCharacter(FSpecials, AnsiChar('['));  AddCharacter(FSpecials, AnsiChar(']'));  AddCharacter(FSpecials, AnsiChar('}'));  AddCharacter(FSpecials, AnsiChar('\'));  AddCharacter(FSpecials, AnsiChar('*'));  AddCharacter(FSpecials, AnsiChar('+'));  AddCharacter(FSpecials, AnsiChar('+'));  AddCharacter(FSpecials, AnsiChar('#'));  AddCharacter(FSpecials, AnsiChar('-'));  AddCharacter(FSpecials, AnsiChar('_'));  AddCharacter(FSpecials, AnsiChar('.'));  AddCharacter(FSpecials, AnsiChar(':'));  AddCharacter(FSpecials, AnsiChar(','));  AddCharacter(FSpecials, AnsiChar(';'));//  AddCharacter(FSpecials, AnsiChar('€'));  AddCharacter(FSpecials, AnsiChar('<'));  AddCharacter(FSpecials, AnsiChar('>'));  AddCharacter(FSpecials, AnsiChar('|'));//  AddCharacter(FSpecials, AnsiChar('µ'));  AddCharacter(FSpecials, AnsiChar('@'));  AddCharacter(FSpecials, AnsiChar('^'));//  AddCharacter(FSpecials, AnsiChar('°'));end; procedure TkzPassword.CreateArrays;begin  ClearArrays;  GenerateNumbers;  GenerateLettersHi;  GenerateLettersLo;  GenerateSpecials;end; procedure TkzPassword.ClearArrays;begin  SetLength(FNumbers, 0);  SetLength(FLettersHi, 0);  SetLength(FLettersLo, 0);  SetLength(FSpecials, 0);  SetLength(FCustom, 0);end; procedure TkzPassword.Generate;var  i: Integer;  LCombined: TAnsiChars;  Len: Integer;  s: AnsiString;begin  s := '';  Len := -1;  LCombined := [];  if FUseNumbers then    for i := Low(FNumbers) to High(FNumbers) do      AddCharacter(LCombined, FNumbers[i]);  if FUseLettersHi then    for i := Low(FLettersHi) to High(FLettersHi) do      AddCharacter(LCombined, FLettersHi[i]);  if FUseLettersLo then    for i := Low(FLettersLo) to High(FLettersLo) do      AddCharacter(LCombined, FLettersLo[i]);  if FUseSpecials then    for i := Low(FSpecials) to High(FSpecials) do      AddCharacter(LCombined, FSpecials[i]);  if FUseCustom then    for i := Low(FCustom) to High(FCustom) do      AddCharacter(LCombined, FCustom[i]);  if FModeSelection = msBits then    if (BitsToChars(FCount) <> -1) then      Len := BitsToChars(FCount);  if FModeSelection = msChars then    Len := FCount;  if ((Len > 0) and (Length(LCombined) > 0)) then    begin      for i := 1 to Len do        s := s + LCombined[Random(Length(LCombined))];    end;  if (s <> '') then    begin      FPassword := s;      if Assigned(FPasswordEvent) then        FPasswordEvent(Self, FPassword);    end;end; end.

Thanks for the demo KodeZwerg it works well also thanks to Tony Stone I take a look at CryptoLib4Pascal

Tony Stone:
Thanks KodeZwerg.  This is basically my generator.  Feel free to tell me it is horrible code.  It does seem to be effective.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- function TfrmMain.CreateRandomPassword(const desiredLen: Integer;  const allowDuplicateCharacters, includeSymbols, includeNumbers, includeUpperCase, includeLowerCase: Boolean): string;var  charSet: string;  i, randomIndex: Integer;  tempChar: Char;begin  Result := '';    if includeUpperCase then charSet := charSet + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';  if includeLowerCase then charSet := charSet + 'abcdefghijklmnopqrstuvwxyz';  if includeNumbers then charSet := charSet + '0123456789';  if includeSymbols then charSet := charSet + SPECIALCHARS;    if (Length(charSet) = 0) or ((not allowDuplicateCharacters) and (desiredLen > Length(charSet))) then  begin    Result := 'Insufficient characters to create a password with the specified criteria.';    Exit;  end;    for i := Length(charSet) downto 2 do  begin    randomIndex := GenerateSecureRandomNumber(1, i);    tempChar := charSet[randomIndex];    charSet[randomIndex] := charSet[i];    charSet[i] := tempChar;  end;    for i := 1 to desiredLen do  begin    randomIndex := GenerateSecureRandomNumber(1, Length(charSet));    Result := Result + charSet[randomIndex];    if not allowDuplicateCharacters then Delete(charSet, randomIndex, 1);  end;end;    


[0] Message Index

[#] Next page

Go to full version