Looking to implement an end user dialog that requires them to create their own password.
Must be 9 characters long. 1 char must be upper case, 1 must be lowercase, one must be a number, ['0'..'9'] and one must be from a set of 6 predefined ascii chars like so. ['!','#','%','&','*','@'].
Have this completed. and works. However, what I wanted to do to was provide visible verification using the onchange event to change the color of the edit box to green if all requirments where met or RED if not. Valdating for the 9 char length is easy enough however checking the 9 various chars to ensure there is at least 1 upper, 1 lower, 1 number and 1 of the predefined is proving a tad difficult. Can anyone help please? Thank you.
This is the code:
procedure TPasswordForm.edtPassword1Change(Sender: TObject);
begin
if Length(edtPassword1.Text <> 9 then
edtPassword1.Color := clRed
else
edtPassword1.Color := clLime;
end;
For fixed char sets function might be quite simple. Note that it does not accept non-Latin chars.
function IsPasswordCrazy(const s: AnsiString): Boolean;
const
C_Upcase = 1;
C_Locase = 2;
C_Digit = 4;
C_SpecSym = 8;
C_All = C_Upcase or C_Locase or C_Digit or C_SpecSym;
var
i, keys: integer;
begin
if Length(s) <> 9 then begin
Result := False;
Exit;
end;
keys := 0;
for i := 1 to Length(s) do
case s[i] of
'A'..'Z': keys := keys or C_Upcase;
'a'..'z': keys := keys or C_Locase;
'0'..'9': keys := keys or C_Digit;
'!','#','%','&','*','@': keys := keys or C_SpecSym;
end;
Result := keys = C_All;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With