Hi all. I'm designing a Visual Basic 2010 forms app. I would like to create a login for this app so that unauthorized users cant use the app. Only people with a username and password can use it. I would like this login to act as a demo too. Explanation follows:

The whole app must expire in a couple of days/tries (like a trial) of the first run.
I (the developer) create the logins for each user. If a normal user logs on, the trial gets activated and won't expire.

If a demo user logs on, the trial's time thing still counts on and expires after a couple of days/tries of the first run..

The user info can be stored in the Settings tab of the VB project or in an Access Database.
I've got coding for a demo app that gets activated (demo gets activated) using a serial. I would like to change this into a login.

The login has to log itself off when the app exits (Security Precaution) and if a demo user logs on the trial starts counting again.

How can I do this?

Recommended Answers

All 13 Replies

One way is to create a class(Public Class User), with username, password, user type and time to expire as properties. My.Settings will accept objects so a List(Of User) can be stored and read quite easily. How this is implemented can be refined when you show the code for the project and itemize what in the code you would like to change.

Why don't you use a serial key? you could have a database online that check to see if the serial code has been activated.

If you would like to go this path I could help you more, but I just shortened it incase you just wanted the way you said.

@joshl: That might work. but I still want the app to logout at the end of a session to avoid unauthorized access, even if it is activated.. I know people will do the same with a login... The login thing will probably be the best here...

Well first off create the basic login form and have it start up first and set the program to fully-close when the last form closes so that way the user logs in then when the right credientials have been entered it will open the main form and close the login window, and if you wanted the program to automatically end the session when the computer isn't being used after a while you can use a timer to track the mouse movements every 0.01 seconds and if the mouse is in the same place for a whole minute then the program will detect that the computer isn't being used and logout.

I hope this helped.

the nice one...
i like it...
this ans may work for you:
- --------------------------------
Make a setting thats called: user (add some more setting for more user as user1, user2)
Make The Shutdown Mode To Shutdown When Last Form Closes
add new Window Form/Login form: (login form) (form1)
Remember Form2 Is The Program It Self
Your login name (here) user1
and as for pass We will add string (setting) as you can change pass too...
- --------------------------------
CODE
Login button

If nametextbox.text = "user1" and passtextbox1.text = my.settings.user1 then
form2.show()
Else
msgbox("oops, you print something wrong",msgboxstyle.critical + msgboxstyle.okonly,"No data found")
End if

sameway you can do for others user...
As to change password:
go to form 2 and then add button change pass.
Form3.show (3 Textbox and 1 button)
textbox1.text = "current pass"
textbox2.text = "new pass"
textbox3.text = "confirm pass"

button_click :

if If textbox1.text = my.settings.user1 then
    if textbox2.text = textbox3.text then
        my.setting.user1 = textbox3.text
    else
        msgbox("Pass do not match")
    End if
else 
        msgbox("Current pass is wrong")
        textbox1.clear()
        textbox2.clear()
        textbox3.clear()
End if    

...you can also import data from database...

Only thing with saving user details in the settings is, the details are being saved to an un ecripted file which means it just takes someone to file the file and they will have the username and password.

So what I would recommend doing is still using that system but use an encrypted password. Use MD5 encryption so when the user goes to login the program will encrypt the entered password and check if it's a match.

Hi joshi 1995..
Hmmm,
I am sorry but I can't understand...
can you show us by creating a simple form. so that we can know about this...

I'm talking about using this kind of system.

Public Class Login

    Public Function StringToMD5(ByVal Content As String) As String
        Dim M5 As New Security.Cryptography.MD5CryptoServiceProvider
        Dim ByteString() As Byte = System.Text.Encoding.ASCII.GetBytes(Content)
        ByteString = M5.ComputeHash(ByteString)
        Dim FinalString As String = Nothing
        For Each bt As Byte In ByteString
            FinalString &= bt.ToString("x2")
        Next
        Return FinalString
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If TextBox1.Text = Nothing Or TextBox2.Text = Nothing Then
            MsgBox("Please enter your username and password", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Empty Fields")
        ElseIf Not TextBox1.Text = My.Settings.Username Or Not StringToMD5(TextBox2.Text) = My.Settings.Password Then
            MsgBox("You have enterd the wrong username or password!", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Wrong Credentials")
        ElseIf TextBox1.Text = My.Settings.Username And StringToMD5(TextBox2.Text) = My.Settings.Password Then
            Main.Show()
            Close()
        End If
    End Sub
End Class

@Mafiamanandre What do you mean you also want to use it as a demo form?

joshl_1995
Yeah, But can you explain me that code.
It work fine but I want to know what about function and difference in simple login and this Login...
I am using simple logging with the setting for all the form wherever I use login.
I like this. I get new things to know from here.
Thank you

Well with program settings, they are saved to the computer (obviously) but they are saved in an unencrypted file, it just takes someone to find the file and they will have the users username and password and just type them in to the login form and there in.

So the way I'm talking about is, doing it that same way just saving the username and password like normal but MD5 encrypt the password so instead of the password looking like this "testingPassword" it will look like this "67dc7d40cca025f9716d41b7bf25c84d". That way no one will be able to find out what it says. Even if they just copy and paste that in to the password textbox it will comback saying that it is the wrong password because it is already encrypted.

Do you know what I'm talking about now?

Joshi_1995
hmmm,
thank you,
I will replace my code with this...
Thank you I learn something more yepee...

Can I get your email please: I just take a look on your site and want to ask something abt that so will you give me?

I've PM'd you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.