If condition problem =(

Results 1 to 4 of 4

Thread: If condition problem =(

  1. #1
    Join Date
    Dec 1969

    Default If condition problem =(

    Hi, I am getting a very strange if condition problem. Anyways, what I am wanting todo is Check a persons username, if the username is found in the database table "users" evaluate a second if statement to make sure the password matchs the username password.<BR><BR>The first if statement is working right, but the second one is not executing for some reason =( <BR><BR>here is the code:<BR>=================<BR>1. do while not rs.eof<BR>2. If UserName = RS("Username") then<BR>3. if Password = RS("Password") Then<BR>4. Session("allow") = True<BR>5. Session("Access") = rs("Access")<BR>6. Response.Redirect ("authoroptions.asp")<BR>7. exit do<BR>8. end if<BR>9. ElseIf Username &#060;&#062; RS("UserName") Then<BR>10. Response.Write ("Sorry wrong Username")<BR>11. ElseIf Password &#060;&#062; RS("Password") Then<BR>12. Response.Write ("sorry wrong password")<BR>13. end if<BR>14. RS.MoveNext<BR>15. loop<BR>===================<BR><BR>If i put a response.write statement between lines 2 and 3 it will print it out, so that means it checked the username and the username was right so it printed out the response.write line. But if I put a response.write statement between lines 3 and 7 it will not do nothing. (i used response.write statments for error checking)<BR><BR>However if i type in a bad username it will call line 9 and it works fine. And if the username and password are both right then it want redirect to authoroptions.asp.... If you would like to see the working example then please goto: <BR><BR><BR>username= Admin<BR>password= admin<BR><BR>Plz help!<BR><BR>Thanks<BR>Bob

  2. #2
    Join Date
    Dec 1969

    Default RE: If condition problem =(

    It appears to me that the way that you have it structured, it can never check the situation where the usesrname is correct and the paassword is incorrect.<BR><BR>At the top if the username is correct, it checks the password. If the password is correct it redirects. If the password is incorrect it exits the loop.<BR><BR>It can only get to the elseif part if the username is incorrect. <BR><BR>Here is the coding I use to check usernames and passwords. <BR>&#060;%<BR>Set DBConn = Server.CreateObject("ADODB.Connection")<BR>Set rst = Server.CreateObject("ADODB.Recordset")<BR>DBConn.O pen "DRIVER=SQL Server;SERVER=intranetx;UID=sa;APP=Microsoft Development Environment;WSID=MMSCWS04;DATABASE=ProjMgmt;User Id=sa;PASSWORD=;"<BR>rst.Open "Select* from tblUsers where Username=&#039" & Request("UserName") &"&#039",DBConn,0,2<BR>If rst.EOF then<BR> response.write("You have entered an invalid user name. Please click your browser&#039s Back button and re-enter your user name.")<BR>Else<BR><BR>If rst("Password") &#060;&#062; Request("Password") Then<BR> response.write("Invalid password for your user name. Please click your browser&#039s Back button and re-enter your password.")<BR>Else<BR>Session("UserType") = rst("UserType")<BR>Session("UserName") = rst("UserName")<BR>Session("Name") = Trim(rst("FirstName") & " " & rst("LastName"))<BR><BR>response.redirect "Home.asp"<BR>End If <BR>End If<BR>%&#062;<BR><BR><BR>Hope this helps<BR><BR>Dennis<BR>

  3. #3
    veena Guest

    Default RE: If condition problem =(

    why don&#039t u use something like<BR><BR>if (username=rs("username") and password=rs("password") so that U can club the two if statements into one

  4. #4
    PMq Guest

    Default RE: If condition problem =(

    If someone&#039s username and password are kept in a single record and you are only evaluating one person at a time, then you should skip the Do...Loop. Just query the table for a record "WHERE username=&#039"&Request("username")&"&#039 AND password=&#039"&Request("password")&"&#039"<BR><BR >Then use an If...Then statement to handle the results.<BR>For example...<BR>&#060;% If RS.EOF Then %&#062;<BR>Sorry, can&#039t find that username/password.<BR>&#060;% Else %&#062;<BR>You&#039re authorized, &#060;%=Request("username")%&#062;. Welcome...<BR>&#060;% End If %&#062;<BR><BR>You can get more elaborate (like validating if it was the username or password that&#039s not found), but this should work fine.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts