Avatar of tryokane
tryokane asked on

How to to check username and password with stored procedure and based on the result output a result to frontend in asp.net?

I have a requirement that when user types in the username and password it has to check username and password at the backend and if username and password exists it has to return a message "Username and Password Exists!" and if username and password dont match it has to give a message like "Invalid User,Register!".How to do this?
.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
tryokane

8/22/2022 - Mon
fanopoe

place a button on your page and, in the onclick event of the button, check that the username and password fields have values in them:
if string.isnullorempty(myUserNameField.Text) then
 'message is "enter a user name"
end if
if string.isnullorempty(myPasswordField.Text) then
 'message is "enter a password"
end if

then create a connection to your database (SQL? Oracle? MySQL?, Access? What are you using as a backend?)
execute whatever command type you like, but I would go with ExecuteNonQuery. You must have a stored procedure on your database to validate the username and password.

I use a label to display messages.
Is there a specific aspect of the validation you are not sure of?
ASKER
tryokane

I am using sqlserver 2000 as backend.How can we write a stored procedure for checking whether only registered users enter into the site?
fanopoe

what is your data structure, i.e. do you have a security table with username & password fields?
if so,something like this would do it:

create procedure pValidateUser(@UserID varchar(20), @Password varchar(20)) as
begin
 select count(1)
 from YourSecurityTable
 where YourUserNameColumn = @UserID
 and YourPasswordColumn = @Password
end

Access this through your data connections on your site. It wil return a 0 if there are no matches, so don't let them login. It will return a 1 if there is a match, and they are allowed to login. I would raise an exception if it returned > 1 because you have identical user accounts.

is that what you need?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER
tryokane

Ok,how do we make this count available to front end so that we decide we can decide on the next action to be done whether to make user login or reject him?
ASKER CERTIFIED SOLUTION
fanopoe

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
tryokane

Yes,Thanks for the Suggestions made.It helped me in solving the problem.