This example is only for educational purposes and shouldn't be used in real world application. Set Edit1.PasswordChar := '*'
Go to the events of your Edit1
component and double clik on OnKeyDown
event. This should generate you a stub for the event. Use this code to fill up the event:
procedure TForm140.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
const
CManagerPassword = 'pass 1';
COperatorPassword = 'pass 2';
begin
if Key = VK_RETURN then
begin
if Edit1.Text = CManagerPassword then
ShowMessage('Logged as Manager')
else if Edit1.Text = COperatorPassword then
ShowMessage('Logged as Operator')
else
ShowMessage('Wrong password');
end;
end;
Compile your program and enter some text in your Edit1
. While typing you should see stars(asterisks) instead of real characters. Hit ENTER key and a message will pop up depending on the password you've entered.
Just remember that you should salt hash all passwords in real application.