Topic: set password

Hi
In my project I have used a password to enter the main form but the user can't change that password set another password.
Is there any way for a user to set his own password for a project.
my script is like this:

procedure frmLogin_bLogin_OnClick (Sender: string; var Cancel: boolean);
begin
    if frmLogin.edPassword.Text = '1' then
    begin
        frmLogin.Hide;
        frmMain.Show;
    end else MessageDlg('Wrong Password', mtError, mbOk, 0); // Displays a red 'X', header is: Error;
end;

Re: set password

Store the password not in the script, but in the database or in the configuration file. For reliability, you can store it in encrypted form.


Alternatively, you can use the standard access control system that is in MVDB.

Визуальное программирование: блог и телеграм-канал.

Re: set password

thank you for your reply
that's exactly what I like o do, but I don't know how to store the password in database or in the configuration file.
How can I do that?

4 (edited by k245 2022-07-04 09:12:21)

Re: set password

  procedure SetStrIni(ASection: string; AKey: string; AVal: string);
  // запись единичного строкового значения в настройки
  var
    tmpIniFile: TIniFile;
  begin
    tmpIniFile := TIniFile.Create(Application.SettingsFile);
    tmpIniFile.WriteString(ASection, AKey, AVal);
    tmpIniFile.Free;
  end;

  function GetStrIni(ASection: string; AKey: string; ADefVal: string = ''): string;
  // чтение единичного строкового значения из настройки
  var
    tmpIniFile: TIniFile;
  begin
    tmpIniFile := TIniFile.Create(Application.SettingsFile);
    Result := tmpIniFile.ReadString(ASection, AKey, ADefVal);
    tmpIniFile.Free;
  end;

procedure frmLogin_bLogin_OnClick (Sender: string; var Cancel: boolean);
begin
    if frmLogin.edPassword.Text = DecryptRC5( GetStrIni('USER','Password'), 'Enigma') then
    begin
        frmLogin.Hide;
        frmMain.Show;
    end else MessageDlg('Wrong Password', mtError, mbOk, 0); // Displays a red 'X', header is: Error;
end;

procedure SetNewPassword;
begin
  SetStrIni('USER','Password',  EncryptRC5( frmNewPassword.edPassword.Text  , 'Enigma')  );
end;
Визуальное программирование: блог и телеграм-канал.

Re: set password

thanks for the script but it shows an error for this line:

if frmLogin.edPassword.Text = DecriptRC5( GetStrIni('USER','Password'), 'Enigma') then

Can you please attach a sample?
thank you so much for your help

Re: set password

I can add an example directly to your project

Визуальное программирование: блог и телеграм-канал.

Re: set password

Thanks for your time
this sample is like my project.

Post's attachments

Attachment icon Students.rar 300.42 kb, 169 downloads since 2022-07-03 

Re: set password

Added a form for change password and a button on the main form. Current password - 123

Post's attachments

Attachment icon Students.rar 301.68 kb, 220 downloads since 2022-07-04 

Визуальное программирование: блог и телеграм-канал.

Re: set password

thank you so much for your help
I can't enter the project, What is the password for the login page?

and also what if you forget the password? is there any way that if you forget the password, you can sett another password?

thanks

Re: set password

123

Destiny

Re: set password

Hi
I have posted this topic a long time ago.
" K245 " inserted a button in the MainForm to change the password.
in the role-based you can change the password from the toolbar.
is it possible that in this sample which is not a role-based access control, the change password is shown on the toolbar?
there is also another problem:
there are two users in this sample , when I change password for one user, the other user's password is also changed

Post's attachments

Attachment icon Students new.rar 301.44 kb, 77 downloads since 2023-07-11 

Re: set password

In your example, there is only one user. Do you happen to confuse program users and students in the database? These are two different concepts.


You can continue to store passwords and users in the initialization file (see example: login 1, password 333, login 2 password 123), but this is not a good solution.


Why don't you want to use the built-in rights management system?

Post's attachments

Attachment icon Students 2.rar 301.72 kb, 110 downloads since 2023-07-11 

Визуальное программирование: блог и телеграм-канал.

Re: set password

thank you for your help
this is the sample with two different users. please check this one

Post's attachments

Attachment icon Students3.rar 301.68 kb, 85 downloads since 2023-07-12 

Re: set password

1. Why do you need a list of users if the password does not depend on the selected user, even if the user is not selected?
2. If the login is successful, the login form is hidden. When "shut down", closing the FrmMain form,
    the process remains hanging in memory, since the login form is not closed.

15 (edited by k245 2023-07-12 12:41:00)

Re: set password

identity wrote:

thank you for your help
this is the sample with two different users. please check this one

Formulate your request correctly. Are you asking to write the script you need?


Do you still want to store passwords in a text file next to the program? They are not very safe in the SQLite database either, but here they just lie in plain sight and say "hack me"  )))

Визуальное программирование: блог и телеграм-канал.

Re: set password

thanks sparrow and k245
I explained my problem incorrectly.
in the sample that I have attached we have 2 different users with 2 different passwords.
What I'm trying to do is to change password for each user using Button1 frmMain and obviously  the password should be depended on the selected user. I should be able to set different passwords for different users
this sample is not  role-based

username: Admin     Password: admin
username: User        Password: user

Post's attachments

Attachment icon ChangePass.rar 297.87 kb, 94 downloads since 2023-07-13 

Re: set password

You fixed the exit error.

Here is your users table


+----+-------+----------+------+-------+--------+--------+---------------+-------+
| id | login | password | read | write | remove | search | administrator | lunch |
+----+-------+----------+------+-------+--------+--------+---------------+-------+
| 1  | admin | admin    | 1    | 1     | 1      | 1      | 1             | NULL  |
| 2  | user  | user     | 0    | 0     | 0      | 0      | 0             | 0     |
+----+-------+----------+------+-------+--------+--------+---------------+-------+



Make conclusions.

Re: set password

What conclusions can I make by this table?
My question still stands
How can I change password using Button1 frmMain?
the button does not work and it doesn't change the password for admin
what i need to do is that when I enter the program with admin I should be able to change admin password
and when I enter as a user I should be able to change user password
I think the script that I used is incomplete.
help me with the script please

Re: set password

Your project works like this:
On startup, you enter the password for the user. When you click on the button,
the password is compared with the password that is stored in the database (sqlite.db) in clear text.
If the password is correct, you enter the program.


When changing the password, you enter the new password and click on the Change button.
In this case, the new encrypted password is written to the INI file.


Nothing bothers you in the described actions??