Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET Login

Posted on 2007-11-29
10
Medium Priority
?
239 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
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

604 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