Database password complexity verification in Inno Setup

Viewed 69

In my setup I need to install SQL server with SA password passed from InputQueryPage. I need to limit password input based on Windows password complexity. The password need to be at least 9 characters long and it has to contain at least one symbol, one uppercase letter, one lowercase letter and one digit. How can do this?

I have this code :

Page0 :=
  CreateInputQueryPage(
    pSelectTasks, 'SQL Server installation', '',
    'Specify SQL Server parameters , press Next to continue.');
       
Page0.Add('SQL Instance:', False);
Page0.Add('Sa Password:', True);
Page0.Values[0] := ('xxx');
Page0.Values[1] := ('xxxxxxx');
2 Answers

solved with this code :

function passwordcomplexity(Pass : String) : Boolean;
var
  i : integer;
  Findchar : Boolean;
begin
    Result := false;
    Findchar:= false;
    begin
      if Length(Pass) < 9 then 
      begin
        Result := False;
      Exit;
    end;

    for i:=1 to length(Pass) do
    begin
        case Pass[i] of
          '!', '"', '§', '$', '%', '&', '/', '(', ')', '=', '?', '\', '*', '#': // caratteri speciali 
          begin
            Findchar := true;
            break; 
          end;
        end;
     end;
  if Findchar = true then 
    begin
    Findchar:= false
    for i:=1 to length(Pass) do
     begin
        case Pass[i] of
        'A'..'Z': // maiuscole
          begin
            Findchar := true;
            break;
          end;
      end;
    end;
  if Findchar = true then 
    begin
    Findchar:= false
    for i:=1 to length(Pass) do
      begin
        case Pass[i] of
        'a'..'z': // minuscole
          begin
            Findchar := true;
            break;
          end;
      end;
    end;
  if Findchar = true then 
    begin
     Findchar:= false
    for i:=1 to length(Pass) do
     begin
        case Pass[i] of
        '0'..'9': // numeri
          begin
            Findchar := true;
            break;
          end;
        end;
      end;
     end;
    end;
   end;
  end;
Result := Findchar ;                                 
end;

See this to find out how to integrate the test into Inno Setup:
Inno Setup - Create User Input Query Page with input length and format limit and use the input

For the actual verification of the password complexity, I'd simplify your code as follows:

function PasswordComplexity(Pass: string): Boolean;
var
  I: Integer;
  AnySymbol, AnyUpper, AnyLower, AnyDigit: Boolean;
begin
  if Length(Pass) < 9 then
  begin
    Result := False;
  end
    else
  begin
    AnySymbol := False;
    AnyUpper := False;
    AnyLower := False;
    AnyDigit := False;

    for I := 1 to Length(Pass) do
    begin
      case Pass[I] of
        '!', '"', '§', '$', '%', '&', '/', '(', ')', '=', '?', '\', '*', '#': 
          AnySymbol := True;
        'A'..'Z':
          AnyUpper := True;
        'a'..'z':
          AnyLower := True;
        '0'..'9':
          AnyDigit := True;
      end;
    end;
    Result := AnySymbol and AnyUpper and AnyLower and AnyDigit;
  end;
end;
Related