Solved

ASP.NET Login

Posted on 2007-11-29
10
227 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
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
 
LVL 12

Expert Comment

by:needo_jee
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:needo_jee
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 12

Expert Comment

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

21 Experts available now in Live!

Get 1:1 Help Now