?
Solved

How to check username and password/Login code in Vb.net

Posted on 2012-03-20
4
Medium Priority
?
443 Views
Last Modified: 2012-03-26
Hi,

I need code for username and password in vb.net using database
0
Comment
Question by:searchsanjaysharma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 37741697
Sometimes it's incredible how you write your questions. We're experts, but not magicians. With the information you supplied it's impossible than any of us can give you a good code... Please, re-write your question providing the information that we need... what database (sql server, oracle, access, mysql...)? what running platform (windows forms, web forms, mvc...)? what version of .net framework? Is the password encrypted in any way? Is is possible that you provide your USERS table name and fields?
0
 

Author Comment

by:searchsanjaysharma
ID: 37741715
When i am descriptive then i get most of the general answers, and there are few experts only who actually reach out to help to solve the problem.

Anyways,
DB Server: Sqlserver
Database : dbac
Table:mstusers
Fields:username and password
Vb.Net 2008.


D
0
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 2000 total points
ID: 37741775
Try this:

    Public Function CheckLogin(ByVal username As String, ByVal password As String) As Boolean
        Dim output As Boolean

        Using connection As SqlConnection = New SqlConnection("your_connection_string")
            connection.Open()

            Using cmd As SqlCommand = New SqlCommand("SELECT COUNT(*) FROM mstusers WHERE username = '" + username + "' AND password = '" + password + "'", connection)
                Dim ret As Integer = cmd.ExecuteScalar()
                output = ret.Equals(1)
            End Using
        End Using

        Return output
    End Function

Open in new window


Hope that helps.
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37767308
ook
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question