Hi All,

I've created a registration form in VB.Net. Now I want to validate it, like if the username is previously used by some one then it wont allow to register. I can do it in ASP.Net, But I m not able to find any solution for VB.Net. If any body have any code snnipet then plz send me or give me few suggestion.

Thanks
M

Dani AI

Generated

Quick, practical summary for : the right pattern is a server-side existence check plus a database-level uniqueness guarantee. and are correct that the app must compare the submitted username to stored records, and ’s point about UI validation (Validating event) covers client/edge checks — but client-side work is only a convenience. Avoid the string-concatenated SQL shown by : it is vulnerable to SQL injection and should not be used.

A compact, safe server-side check (VB.NET) uses a parameterized query and ExecuteScalar to test existence:

Using cn As New SqlConnection(connectionString)
    Using cmd As New SqlCommand("SELECT COUNT(1) FROM Users WHERE UserName = @u", cn)
        cmd.Parameters.AddWithValue("@u", userNameTextBox.Text.Trim().ToLower())
        cn.Open()
        Dim taken As Integer = Convert.ToInt32(cmd.ExecuteScalar())
        If taken > 0 Then
            ' handle "username taken"
        Else
            ' proceed to create account (hash password first)
        End If
    End Using
End Using

Enforce uniqueness at the database level (prevents race conditions):

ALTER TABLE Users
ADD CONSTRAINT UQ_Users_UserName UNIQUE (UserName);

Extra notes: normalize usernames (trim, lowercase, restrict allowed characters), validate on both client and server, and never store plain-text passwords — use a strong hash (PBKDF2/bcrypt/Argon2) or a framework account system. For web forms combine RequiredField/Custom validators with the server-side check; for desktop apps use the Validating event as a convenience but still verify on the server before creating the account.

Recommended Answers

All 5 Replies

you just check each of the value in registration form with data in your database, what the problems...
if u can save and show data from database so its not difficult to validate registration from with database.

if you can do in asp.net with vb, it think you can do the same. so what the effort of your code?

for validation you have to follow this


1 compare the text value with each user name record field.

2. if any record find out with same name you have to given message to user "user name all ready used by some one you have to chose another name" .


3. if no record is found create and save to data base.


for any type of web related information you can visit
http://webdesigningcompany.net

'declare connectionstring to server

    'assuming your table name where users are stored is called 'Users' 
    'and the column name to verify a user is called 'username'

    Dim SelectStmt As String = "SELECT * FROM users WHERE UserName ='" +   userNameTextBox.Text + "' and " + _
                "Password ='" + passwordTextBox.Text + "'"

    Dim dc As SqlCommand = New SqlCommand(SelectStmt, con) 'assming your connectionstring is called 'con'

    Dim reader As SqlDataReader = objcommand.ExecuteReader

    If reader.Read Then

	'enter codes on what the system should do if the user exists

    Else

   MessageBox.Show("Invalid Username or Password!", "Login Error", _
                MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning)
    End if
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.