Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I store passwords locally for a multi-user application?

I want to create a multi-user application, but I don't know how to save and read encrypted passwords.

procedure SavePass(Password: WideString);
var
  Pass: TIniFile;
begin
  Pass := TIniFile.Create(ChangeFileExt(Application.ExeName, '.PASS'));
  Pass.WriteString('Users', 'USERNAME', Password);
  Pass.Free;

The passwords must be stored on the computer. This works but it's stupid to save passwords using this. Hashing passwords would be also good.

like image 900
Little Helper Avatar asked Dec 05 '22 22:12

Little Helper


2 Answers

If the connecting software accepts hashed passwords, it's not going to stop people who steal the hashed passwords from connecting. All it will do is hide what the real password is.

Furthermore, if the software that you're connecting to does not accept hashed passwords (database, website, ...), you're going to have to store your password in such a way that you can get it back to its original state. A hashed version is not going to help you there.

If you want to scramble your storage so that humans cannot read the file, you could use Windows.EncryptFile() and Windows.DecryptFile(). In newer Delphi's that's neatly wrapped into IoUtils.TFile.Encrypt() and IoUtils.TFile.Decrypt.

If you really want to stop others from reading the cleartext version of your password, you're going to have to use some encryption with a key. Where do you store that key then?That would defeat the whole purpose of storing a password in the first place. It's better to prevent access by other users by using user privileges to the file system for example, because anything you or your software can do, a "hacker" can do if he has the same privileges.

like image 185
Wouter van Nifterick Avatar answered May 14 '23 23:05

Wouter van Nifterick


My suggestion is to not use passwords in your application at all, unless you really need to. The user experience of having yet another password to enter & remember is usually not needed.

What I do for my applications is default to using the domain and user name of the current user as the identification. The user has already logged on with a password, or more secure system if they want it. Only by logging on can they be that current user. My server then accepts that as their identification.

Variations on this include optionally passing the machine name too, so that the same user is treated differently on different computers (when they need to use more than once computer at once). And of course you can still allow a normal password if you want to.

like image 26
mj2008 Avatar answered May 15 '23 00:05

mj2008