how to create a simple logi form in vb.net without using database connection???

Dani AI

Generated

For a local, no-database login the safest approach is to avoid hardcoding credentials and to avoid storing passwords in clear text. 's quick hardcoded check is fine as a learning example and 's note about the VB.NET Login Form template is a handy UI shortcut, while rightly warns about plain-text storage. A practical pattern for single-machine apps is: store only a salted, iterated hash on disk, protect that file with the OS (or DPAPI), and verify with a constant-time comparison.

Example — create and verify a salted PBKDF2 hash in VB.NET:

Function CreatePasswordHash(password As String) As String
    Dim saltSize As Integer = 16
    Dim hashSize As Integer = 32
    Dim iterations As Integer = 100000 ' choose a strong work factor appropriate for the environment
    Dim salt(saltSize - 1) As Byte
    Using rng As New System.Security.Cryptography.RNGCryptoServiceProvider()
        rng.GetBytes(salt)
    End Using
    Dim pbkdf2 As New System.Security.Cryptography.Rfc2898DeriveBytes(password, salt, iterations)
    Dim hash As Byte() = pbkdf2.GetBytes(hashSize)
    Return iterations.ToString() & ":" & Convert.ToBase64String(salt) & ":" & Convert.ToBase64String(hash)
End Function

Function VerifyPassword(password As String, stored As String) As Boolean
    Dim parts() As String = stored.Split(":"c)
    If parts.Length <> 3 Then Return False
    Dim iterations As Integer = Integer.Parse(parts(0))
    Dim salt As Byte() = Convert.FromBase64String(parts(1))
    Dim storedHash As Byte() = Convert.FromBase64String(parts(2))
    Dim pbkdf2 As New System.Security.Cryptography.Rfc2898DeriveBytes(password, salt, iterations)
    Dim computedHash As Byte() = pbkdf2.GetBytes(storedHash.Length)
    Dim diff As Integer = storedHash.Length Xor computedHash.Length
    For i As Integer = 0 To Math.Min(storedHash.Length, computedHash.Length) - 1
        diff = diff Or (storedHash(i) Xor computedHash(i))
    Next
    Return diff = 0
End Function

Operational notes and cautions: write the stored string to a file under the user's AppData with strict ACLs, or encrypt the file with ProtectedData (DPAPI) before saving. Never check credentials into source control. For anything beyond a tiny single-user demo, prefer a proper authentication mechanism (Windows credentials, a small secured database, or an identity provider), enable account lockout/logging, and use TLS for networked scenarios.

Recommended Answers

All 3 Replies

till now i dont do much vb.net but i am familiar to vb6 , so on the basis of vb6 i am giving you a answer

i dont understand why you are making login form without database connection, but if you really dont wanna use it , then try it:-

If Text1.Text = "user name" And Text2.Text = "user password" Then
MsgBox "login successful"
Else
MsgBox "incorrect detail"
End If

hope this helps you ...

VB.net has a login form template that you can use. Just Add -> New Item to your project and choose Login Form

In my opinion, coding a password into the program itself is asking for trouble. If I were you, I would save the password into an external text file first. Then, when the form loads, check to see if that file exists, read the text from it and then run a check to confirm that the user given password matches that in the saved file. For added security, you could create a form that runs on first use to ask the user for a password, then save the password into a user defined location with some simple encryption.

Hope this helps.

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.