Groups

    Help needed with asp scripting

    Hi

    Any ASP coder's in here.

    Ive set up a web page which asks for a username and password.

    What i need now is help with scriping the following.

    if user1 & password 1 are correct redirect to = userpage1.asp
    if user2 & password 2 are correct redirect to = userpage2.asp
    if user3& password 3 are correct redirect to = userpage3.asp

    is this possible with out databases ?

    18 Comments

    what do you mean by user 1 & password 1

    just static user names e.g admin admin ?

    how many users are you planning of having ?

    is this production or playing if it is just playing just hard code it

    Original Poster

    moulez;5656362

    what do you mean by user 1 & password 1 just static user names e.g admin … what do you mean by user 1 & password 1 just static user names e.g admin admin ?how many users are you planning of having ?is this production or playing if it is just playing just hard code it



    i mean

    if user one enter there username and password as

    admin1 and password then they will get directed to userpage1.asp

    if user 2 enter there username and password as

    admin2 and password then they will get directed to userpage2.asp

    hope that makes more sense

    is there a limited amount of users (i.e. can you hard code the usernames etc ) or do you want to add users in this system ?

    if not just have a massive if statement for each user

    Pusedo code:

    if(username=="user1"&&pass=="pass"){
    // direct to page 1 for that user
    }
    else if(username=="user2"&&pass=="pass2"){

    }

    if u need more than a set ammount you will have to read in from file if you dont want to store on a DB

    another option is to have a massive array of users but this wont be persistant e.g. when it restarts any new users u add will be lost

    Original Poster

    moulez;5657214

    if not just have a massive if statement for each user Pusedo … if not just have a massive if statement for each user Pusedo code:if(username=="user1"&&pass=="pass"){// direct to page 1 for that user }else if(username=="user2"&&pass=="pass2"){}if u need more than a set ammount you will have to read in from file if you dont want to store on a DB another option is to have a massive array of users but this wont be persistant e.g. when it restarts any new users u add will be lost




    there will only be about 5 users, i will give your sulotion a go over the weekend. many thanks

    will let you know how i get on :thumbsup:

    Original Poster

    ive been playin with the code, but it still doesnt work. this is my code below


    Sub CheckLoginForm
    'check if the value of the text field 'username' and 'password' are correct
    If Request.Form("username") = "mic" AND Request.Form("password") = "pass" Then
    Session("BlnLoggedIn") = True
    Response.Redirect "svideo1.asp"
    If Request.Form("username") = "mic2" AND Request.Form("password") = "pass2" Then
    Session("BlnLoggedIn") = True
    Response.Redirect "svideo2.asp"
    Else
    'if the values entered are incorrect then display the message below
    Response.Write "
    You are not logged in.

    "
    ShowLoginForm
    End If
    End Sub
    %>

    hi there

    it looks like you may have already seen this but have you tried this link

    codefixer.com/tut…asp

    it is a good tutorial on how to get it up and running, the code you pasted doesn't have any obvious problems so im thinking it may be a problem else where, it may be worth breaking the if statement down in to obvious things to make sure the re-direct thing works etc

    let me know how you get on

    Original Poster

    moulez;5672332

    hi there it looks like you may have already seen this but have you tried … hi there it looks like you may have already seen this but have you tried this link http://www.codefixer.com/tutorials/password_protect.aspit is a good tutorial on how to get it up and running, the code you pasted doesn't have any obvious problems so im thinking it may be a problem else where, it may be worth breaking the if statement down in to obvious things to make sure the re-direct thing works etclet me know how you get on



    hi there

    ive got it to work so 1 user can login but it doesnt work for the 2nd and 3rd users

    i spotted your problem there i think

    incorrect login in your if statements

    you go ....

    if user1 then
    ,,,
    if user2 then
    ...
    else
    ....

    this means if it is not user on or user two it will break because the else will pick it up

    it should be

    if user1 then{
    log user1
    }
    else if user2 then{
    log user 2
    }
    else if user3 then{
    log user 3
    }
    else{
    "no users match so end it "
    }


    i think this may be related to your problem

    p.s. this is the syntax you should be using

    If A=B Then
    response.write "A is equal to B"
    ElseIf A=C
    response.write "A is equal to C"
    ElseIf A=D
    response.write "A is equal to D"
    Else
    response.write "A doesn't equal any of them"
    End If
    %>

    hope this helps

    Hmmmm, any particular reason you want to do it that way? That's about as secure as a jelly padlock.

    First things first, you should set the Session("BlnLoggedIn") = False before the If statements.

    Also the second 'If' statement should be 'ElseIf' like moulez has suggested.

    yer im assuming this is a project or a proof of concept or something as this isn't "industry standard" when it comes to log on pages

    Original Poster

    cheers guy, but how would i script the following to work?

    If A=B Then
    response.write "A is equal to B"
    ElseIf A=C
    response.write "A is equal to C"
    ElseIf A=D
    response.write "A is equal to D"
    Else
    response.write "A doesn't equal any of them"
    End If
    %>


    would it be something like

    If user=user1 Then
    response.redirect "page1.asp"
    ElseIf user=user2
    response.redirect "page2.asp"
    ElseIf user=user3
    response.redirect "page3.asp"
    Else
    response.write "A doesn't equal any of them"
    End If
    %>

    rashriaz;5679585

    cheers guy, but how would i script the following to work?If A=B … cheers guy, but how would i script the following to work?If A=B Thenresponse.write "A is equal to B"ElseIf A=Cresponse.write "A is equal to C"ElseIf A=Dresponse.write "A is equal to D"Elseresponse.write "A doesn't equal any of them"End If%>would it be something likeIf user=user1 Thenresponse.redirect "page1.asp"ElseIf user=user2response.redirect "page2.asp"ElseIf user=user3response.redirect "page3.asp"Elseresponse.write "A doesn't equal any of them"End If%>



    Pseudocode fine to me, are you still having problems?

    If Request.Form("username") = "mic" AND Request.Form("password") = "pass" … If Request.Form("username") = "mic" AND Request.Form("password") = "pass" Then response.redirect "page1.asp"ElseIf Request.Form("username") = "mic2" AND Request.Form("password") = "pass2" response.redirect "page2.asp"ElseIf Request.Form("username") = "mic3" AND Request.Form("password") = "pass2" response.redirect "page3.asp"Else response.write "A doesn't equal any of them"End If%>



    your looking for something close to this

    just your orig code with else ifs in to make the logic work

    Original Poster

    if not tried it yet, will give it a go later

    thanks

    Original Poster

    Thanks everyone, espically moulez

    Now working perfectly

    Dont worry about it mate

    i understand how hard it is to get your head around this stuff at the start


    good to hear its working
    Post a comment
    Avatar
    @
      Text
      Top Discussions
      1. WONGA REFUNDS DUE2111019
      2. miikeyblue and shabbird's (but mostly shabbird's) Tuesday night pub quiz!553770
      3. Do you have one of these 2.1 million 50p's selling for 20x its value?58
      4. Just heard this...2 ★★★★★★★★★★★★★★ congrats to all on 392k ★★★★★★★★★★★★★★7767186

      See more discussions