-2

I am new in this site as well as I am a beginner in Delphi programming.. my project is a supermarket management application used by Arabic users ...for the GUI ,I just want to make a Tedit that accepts two kinds of passwords (one for the manager /one for each P.O.S operator) Please I need some ideas, hints or other ways to make such action possible for my project

Thanks in Advance :)

Hai-Lag
  • 1
  • 1
  • If you login with a user name and a password combination, you would know which password to compare with. – LU RD Jul 07 '15 at 06:07
  • Compare the value entered against the possible passwords in turn. – David Heffernan Jul 07 '15 at 06:09
  • 1
    This is a very broad question. Which part of this project are you having problems with? Do you know how to create a `TEdit`? Do you know how to capture data from a `TEdit`? Do you need help comparing that captured data against a password store? Do you need help hashing and storing your user's passwords? Do you have a database? If yes, do you need help setting up the tables for this part of the project? If no, do you need help installing and configuring a database? Try to break the problem down into smaller pieces - ask more specific questions where you are stuck. – J... Jul 07 '15 at 10:12

1 Answers1

0

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.

Wodzu
  • 6,932
  • 10
  • 65
  • 105
  • Encryption isn't the standard way to handle passwords. Salted hashing is. And why use a mask edit. Standard edit can do this fine? – David Heffernan Jul 07 '15 at 06:16
  • You are right, they must have added `TEdit.PasswordChar` along the way. As for the password encryption, this wasn't suppose to be cryptography lesson but I've changed the sentence. – Wodzu Jul 07 '15 at 06:28
  • 1
    The problem with this answer is that it only answers part of the question. Furthermore, it may or may not answer the part that OP actually needs help with. This is naturally because the question is low quality, overly broad, and rather vague. It is perhaps better to help OP improve the question first... – J... Jul 07 '15 at 10:07
  • What part of question isn't addressed in this answer? _"I just want to make a Tedit that accepts two kinds of passwords (one for the manager /one for each P.O.S operator)"_ - this is quite clear for me, but maybe I am missing something here. – Wodzu Jul 07 '15 at 10:11
  • 1
    If that is the question, then I could equally answer *"Drag a TEdit onto your form"* -- job done. Now you have made a `TEdit` that will accept any kind of password (or anything else, for that matter). What do you need this awful code (that would never be used in real life for anything!) for? – J... Jul 07 '15 at 10:17
  • Consider that the only sane place this data should be coming from is a database. Whether manager or not should be a column in the user table - the entire implemenation is not going to look anything like this at all. Given that, this really only usufelly answers the question : `How do I retrieve string data typed into a TEdit?`. At that, it provides only one way to do that. This isn't your fault - the question is bad and there is no good way to answer it. That's my only point. – J... Jul 07 '15 at 10:26
  • Actually, I take that back - LDAP/ActiveDirectory is perhaps a viable alternative to a database store. Maybe there are at least two sane places the data could be coming from... – J... Jul 07 '15 at 16:20