Click here to Skip to main content
14,697,418 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,
Can someone tell me how to store correct admin value in project settings, when admin logins to program to store his record to project until he logout or exit program.
It's important to lose the record back to 0 when exit program or signout, because more people will use the same pc.

Here is my code for login:
Public Sub Loggin()
        If Login.txtUsername.Text = "" Or Login.txtPassword.Text = "" Then
            MsgBox("Please enter Username and Password!")
            Login.txtUsername.Focus()
        Else
            Try
                With cmd
                    conn.Open()
                    .Connection = conn
                    .CommandText = "Select * From Accounts WHERE Accname = @GetLogin and Accpass = @GetPass"
                    .Parameters.AddWithValue("@GetLogin", Login.txtUsername.Text)
                    If Encr >= 1 Then
                        .Parameters.AddWithValue("@GetPass", Encrypt.EncryptPassword(Login.txtPassword.Text))
                    ElseIf Encr = 0 Then
                        .Parameters.AddWithValue("@GetPass", Login.txtPassword.Text)
                    End If

                    'Starting The Query
                    Adapter.SelectCommand = cmd
                    Reader = cmd.ExecuteReader
                    .Parameters.Clear()
                    'Validate User
                    If Reader.HasRows = 0 Then
                        'Login.ProgressBar1.Value = 0
                        Login.txtUsername.Text = ""
                        Login.txtPassword.Text = ""
                        Login.txtUsername.Focus()
                        Return
                    Else
                        Dim authorityid = 0
                        While Reader.Read()
                            authorityid = Reader.Item("Admin")
                        End While
                        If authorityid = 1 Then
                            'Login Admin User
                            'AdminMenu.Show()
                            Login.Close()
                        ElseIf authorityid = 0 Then
                            'Login Normal User
                            MainCP.Show()
                            Login.Close()
                        ElseIf authorityid > 1 Then
                            MessageBox.Show("Error in Database User Information", "Visual WMS", MessageBoxButtons.OK, MessageBoxIcon.Warning)
return
                        Else
                            'Login.ProgressBar1.Value = 0
                            Login.txtUsername.Text = ""
                            Login.txtPassword.Text = ""
                            Login.txtUsername.Focus()

                        End If
                    End If
                End With
            Catch ex As Exception
                MsgBox(ex.Message)
                'MsgBox("Please check your Settings.ini File")
            Finally
                Reader.Close()
                Adapter.Dispose()
                cmd.Dispose()
                If conn IsNot Nothing Then
                    conn.Close()
                End If
            End Try
        End If
    End Sub


What I have tried:

in project:
- Settings> isAdmin boolen user false

If authorityid = 1 Then
                            'Login Admin User
                            'AdminMenu.Show()
                            My.Settings.isAdmin = 1
                            Login.Close()
Posted
Updated 7-Sep-20 8:27am
v2
Comments
Richard Deeming 7-Sep-20 13:10pm
   
You're storing passwords in plain text. Don't do that.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
Richard Deeming 7-Sep-20 13:10pm
   
Besides that, if you want to forget the value when the program exits, why are you storing it in the settings at all? The settings are for storing values which need to be remembered between executions of your program.
diablo22 7-Sep-20 13:25pm
   
because i want to store it in program, cause when admin login will have stuff that he can see only in program others will not see it :)
Richard Deeming 7-Sep-20 13:29pm
   
There are other options to store things in memory whilst your program is running which won't be stored when the program exits.

For example, Shared variables.

1 solution

My.Settings.isAdmin = True


also i will just use when exit application:

My.Settings.Reset()
Application.Exit()

seems to work normal with few tests no records or bugs find.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900