Solved

ASP.NET Login

Posted on 2007-11-29
10
226 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
  • 6
  • 4
10 Comments
 
LVL 12

Accepted Solution

by:
needo_jee earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
needo_jee:

Never mind...I should have walked myself through your code before I responded...points being awarded now.
0
 
LVL 12

Expert Comment

by:needo_jee
Comment Utility
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:needo_jee
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 12

Expert Comment

by:needo_jee
Comment Utility
dont worry about awarding points. if your problem has not been resolved yet.. I am here .. :)
0
 

Author Comment

by:lrbrister
Comment Utility
Using Visual STudio 2005
0
 
LVL 12

Expert Comment

by:needo_jee
Comment Utility
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
Comment Utility
needo_jee
Your soliutions all were very good.  Thanks for the help
0
 
LVL 12

Expert Comment

by:needo_jee
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now