?
Solved

ASP.NET Login

Posted on 2007-11-29
10
Medium Priority
?
234 Views
Last Modified: 2013-11-26
I have the select statement below my following vb code in a called stored procedure...

How do I get my vb code to do something based on what's returned...

I don't know what to do when the 'Incorrect Email' or "Incorrect password" is returned.

If dR.HasRows Then
                If dR("ttlLogins") < 3 Then
                    Response.Redirect("home.aspx?page=profile")
                Else



SQL Server code.

blah...blah...clah...
IF NOT EXISTS (SELECT * FROM  dbo.tblUsers WHERE Email = @Email)    
      RETURN 'Incorrect Email'
ELSE
BEGIN
    IF NOT EXISTS (SELECT * FROM  dbo.tblUsers WHERE Email = @Email AND UserPassword = @UserPassword)
             RETURN 'Incorrect Password'
    ELSE
              select userID,email,UserPassword,
from  dbo.tblUsers where email = @Email and  UserPassword = @UserPassword

0
Comment
Question by:lrbrister
[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
  • 6
  • 4
10 Comments
 
LVL 12

Accepted Solution

by:
Munawar Hussain earned 2000 total points
ID: 20379833
There could be many possible paths; by using different SQL Queries and VB combinations. you may use

SELECT COUNT(*) FROM tblUsers where userName=@userName and Password=@password

' IN VB you may check
If dR.HasRows Then ' that mean rows are returned coz records is matched
If dR.read() Then
Response.Redirect("home.aspx?page=profile")
Else

end if

*********************************** OR use
IF NOT EXISTS (SELECT * FROM  dbo.tblUsers WHERE Email = @Email)    
SELECT 0 AS Result -- just a flag value
ELSE
BEGIN
    IF NOT EXISTS (SELECT * FROM  dbo.tblUsers WHERE Email = @Email AND UserPassword = @UserPassword)
select 1 as Result -- a flag value
    ELSE
     select userID,email,UserPassword,
          from  dbo.tblUsers where email = @Email and  
         UserPassword =  @UserPassword


********** vb code **********
if its vb.net then you check
If dR.HasRows Then
''                If dR("ttlLogins") < 3 Then
if dR.FieldCount > 1 ' means there are uname, pass
                    Response.Redirect("home.aspx?page=profile")
                Else
only one column . .comes here check for 0 or 1 (means wrong uname or pass)
if dR.GetValue(0)  = 0 then
wrong email
else if dR.GetValue(0) = 1 then
wrong pass
end if

thanks
0
 

Author Comment

by:lrbrister
ID: 20379894
needo_jee:

 My SQL query returns three possible sets of data

'Incorrect Email'
"IncorrectPassword"

and a dataset...

I need to know how do do something if one of the first two comes back...
'Incorrect Email'
"IncorrectPassword"

My I know what to do if dR("email") comes back.  HOW do I do that?

0
 

Author Comment

by:lrbrister
ID: 20379898
needo_jee:

Never mind...I should have walked myself through your code before I responded...points being awarded now.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 12

Expert Comment

by:Munawar Hussain
ID: 20380237
are you using VB.Net? if yes then you may use above code correctly
I just replaced  2 lines with codes 0 and 1 .. just to make checking easy at code side?

'Incorrect Email' = 0
"IncorrectPassword" = 1

**********************
There could be many possible paths; by using different SQL Queries and VB combinations. you may use

SELECT COUNT(*) FROM tblUsers where userName=@userName and Password=@password

' IN VB you may check
If dR.HasRows Then ' that mean rows are returned coz records is matched
If dR.read() Then
Response.Redirect("home.aspx?page=profile")
Else

end if

*********************************** OR use
IF NOT EXISTS (SELECT * FROM  dbo.tblUsers WHERE Email = @Email)    
SELECT 0 AS Result -- just a flag value
ELSE
BEGIN
    IF NOT EXISTS (SELECT * FROM  dbo.tblUsers WHERE Email = @Email AND UserPassword = @UserPassword)
select 1 as Result -- a flag value
    ELSE
     select userID,email,UserPassword,
          from  dbo.tblUsers where email = @Email and  
         UserPassword =  @UserPassword


********** vb code **********
if its vb.net then you check
If dR.HasRows Then
if dR.FieldCount > 1 ' means there are uname, pass
                    Response.Redirect("home.aspx?page=profile")
                Else
only one column . .comes here check for 0 or 1 (means wrong uname or pass)
if dR.GetValue(0)  = 0 then
wrong email
else if dR.GetValue(0) = 1 then
wrong pass
end if

0
 
LVL 12

Expert Comment

by:Munawar Hussain
ID: 20380247
are you using VB.Net? if yes then you may use above code correctly
I just replaced  2 lines with codes 0 and 1 .. just to make checking easy at code side?

'Incorrect Email' = 0
"IncorrectPassword" = 1

**********************
There could be many possible paths; by using different SQL Queries and VB combinations. you may use

SELECT COUNT(*) FROM tblUsers where userName=@userName and Password=@password

' IN VB you may check
If dR.HasRows Then ' that mean rows are returned coz records is matched
If dR.read() Then
Response.Redirect("home.aspx?page=profile")
Else

end if

*********************************** OR use
IF NOT EXISTS (SELECT * FROM  dbo.tblUsers WHERE Email = @Email)    
SELECT 0 AS Result -- just a flag value
ELSE
BEGIN
    IF NOT EXISTS (SELECT * FROM  dbo.tblUsers WHERE Email = @Email AND UserPassword = @UserPassword)
select 1 as Result -- a flag value
    ELSE
     select userID,email,UserPassword,
          from  dbo.tblUsers where email = @Email and  
         UserPassword =  @UserPassword


********** vb code **********
if its vb.net then you check
If dR.HasRows Then
   if dR.FieldCount > 1 ' here is your dataset (because it will return 3 columns)
                    Response.Redirect("home.aspx?page=profile")
                Else
  ' only one column . .comes here check for 0 or 1 (means wrong uname or pass)
   else if dR.GetValue(0)  = 0 then ' here is if 'Incorrect Email'
'wrong email
  else if dR.GetValue(0) = 1 then ' here is IncorrectPassword"
 ' wrong pass
  end if
end if


if still having any problem . kindly let me know.
Please just make me sure .. are you using vb.net?
Thanks
0
 
LVL 12

Expert Comment

by:Munawar Hussain
ID: 20380250
dont worry about awarding points. if your problem has not been resolved yet.. I am here .. :)
0
 

Author Comment

by:lrbrister
ID: 20381183
Using Visual STudio 2005
0
 
LVL 12

Expert Comment

by:Munawar Hussain
ID: 20381226
I believe the above code should work without any problem but if you want to use some specific code structure and for that you think it is not enough or not worthy for you then let me know..
Thanks
0
 

Author Comment

by:lrbrister
ID: 20381403
needo_jee
Your soliutions all were very good.  Thanks for the help
0
 
LVL 12

Expert Comment

by:Munawar Hussain
ID: 20381561
For me it is important that the person got what s/he was looking for. If it has solved your problem then I am the happiest man of the world this time..
cheers..
Thanks :)
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

770 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