Solved

ASP.NET Login

Posted on 2007-11-29
10
232 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:
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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
 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In this article I will describe the Backup & Restore 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.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

728 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