0
<%@ language = "VBScript"%>
<!DOCTYPE html>
<html>
<body>
<form method="post" action="">
Username:<br> <input type = "text" name = "user"/><br>
Password:<br> <input type = "password" name = "pass"/><br>
<input type = "submit" name = "register_button" value = "Register"/>
<input type = "submit" name = "submit_button" value = "Submit"/>
</form> 

<%
set credentials = Server.CreateObject("Scripting.Dictionary")
set Session("credentials") = credentials 

if Request.form("register_button") <> "" then
    dim user
    dim pass
    pass = Request.form("pass")
    user = Request.form("user")

    Session("credentials").Add user, pass   
end if

if Request.form("submit_button") <> "" then 
    dim userd
    dim passd
    passd = Request.form("pass")
    userd = Request.form("user")
    if Session("credentials").Exists(userd) = true then
        if Session("credentials").Item(userd) = passd then
            Response.Write("ACCESS GRANTED")
        else 
            Response.Write("ACCESS DENIED")
        end if
    else
        Response.Write("USERNAME DOES NOT EXIST")
    end if
end if
%>

</body>
</html>

So this is a basic login page I created using Classic ASP. When I type in a user and pass, then click Register, it stores the username and password in the Dictionary no problem. But, when I click the submit button (after filling in the registered credentials), somehow the contents of the dictionary get deleted. So, it fails the "if Session("credentials").Exists(userd) = true then" statement. I even tried making "credentials" a normal variable, without using Session. It still won't work, the dictionary's contents just get deleted. How can I overcome this problem? Thanks in advance!

5
  • 1
    I would rethink this approach; stackoverflow.com/questions/2076165/…
    – Alex K.
    Jan 21, 2014 at 16:05
  • Well because I'm still a beginner in ASP, I only wanted to store the credentials in a Dictionary. I want to avoid using Databases for the time being. With that said, what approach do you suggest I should take? Would storing the credentials in a query string work? I'm just doing this for learning purposes so it doesn't have to be secure. Jan 21, 2014 at 17:57
  • The session is already like a dictionary so I would just store the values directly; Session("pass") = "xyz" / Session("user") = "bob"
    – Alex K.
    Jan 21, 2014 at 17:58
  • Interesting, I'll give it a shot Jan 21, 2014 at 18:04
  • @AlexK. better post this as answer, sometimes the most simple things evade us. Jan 24, 2014 at 22:41

1 Answer 1

0

this first credentials.Add user, pass

set Session("credentials") = credentials
should be after

2
  • Hey George, welcome on board :) may you please further elaborate on your answer. A first step would be to format code lines, a second step would be to add more detailed instructions on what to do.
    – Lausbert
    Dec 8, 2018 at 23:18
  • please consider to provide more description. and format your post accordingly Dec 8, 2018 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.