Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE PROCEDURE dbo.AuthenticateLogin(
- @Username VARCHAR(100),
- @Password VARCHAR(100),
- @response NVARCHAR(500) OUTPUT
- )AS
- BEGIN
- DECLARE @UserID INT
- IF(EXISTS(SELECT username FROM users WHERE username = @Username))
- BEGIN
- SET @UserID = (SELECT users_id FROM users WHERE username = @Username AND user_password = @Password)
- IF @UserID IS NULL
- SET @response = 'Incorrect Password'
- ELSE
- Set @response = 'Success'
- END
- ELSE
- SET @response = 'Invalid Login'
- END
- GO
- Public Function AuthenticateLogin(ByVal username As String, ByVal password As String) As Boolean
- Dim CMD As New SqlCommand("AuthenticateLogin")
- CMD.Parameters.Add("@UserName", SqlDbType.VarChar).Value = username
- CMD.Parameters.Add("@Password", SqlDbType.VarChar).Value = password
- AuthenticateLogin = ExecuteCMDWithReturnValue(CMD)
- End Function
- Public Function ExecuteCMDWithReturnValue(ByRef CMD As SqlCommand) As Boolean
- Try
- OpenDBConnection()
- CMD.Parameters.Add("@response", SqlDbType.NVarChar).Direction = ParameterDirection.ReturnValue
- CMD.Connection = DB_CONNECTION
- CMD.CommandType = CommandType.StoredProcedure
- CMD.ExecuteNonQuery()
- Dim result As Object = CMD.Parameters("@response").Value
- Return If(Convert.ToInt32(result) = 1, False, True)
- Catch ex As Exception
- Throw New Exception("Database Error: " & ex.Message)
- Return False
- Finally
- CloseDBConnection()
- End Try
- End Function
Add Comment
Please, Sign In to add comment