Checking Password

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vasuki Masilamani
    New Member
    • Dec 2006
    • 18

    Checking Password

    Hi, Please find the simple code below for checking password.

    <HTML>
    <Body>
    <h2>Checking the Password</h2><br><hr>

    <Form name=form1>
    Enter the Password:
    <Input type=password name=text1>
    <br>
    <Input type=button name=button1 value="Check">
    <br><hr>

    <h2>Changing the Password</h2><br><hr>
    Enter the New Password:
    <Input type=password name=text2>
    <br>
    <Input type=button name=button2 value="Change">
    <br>
    </Form>
    <Script language="vbscr ipt">
    dim pass,a
    pass="rajeev"
    Sub button1_Onclick ()
    if (Form1.text1.va lue=pass)then
    msgbox "Password Correct"
    else
    msgbox "Password Incorrect"
    endif
    End Sub

    Sub button2_OnClick ()
    if (Form1.text2.va lue<>pass)then
    msgbox "Password Changed"
    else
    msgbox "Invalid Password"
    endif
    End Sub
    </Script>
    </Body>
    </HTML>

    This code is not working.. I dont know what mistake i have done. Please help me in solving this problem.. Thanks in advance..

    Thanks,
    Vasuki
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    Originally posted by Vasuki Masilamani
    Hi, Please find the simple code below for checking password.

    <HTML>
    <Body>
    <h2>Checking the Password</h2><br><hr>

    <Form name=form1>
    Enter the Password:
    <Input type=password name=text1>
    <br>
    <Input type=button name=button1 value="Check">
    <br><hr>

    <h2>Changing the Password</h2><br><hr>
    Enter the New Password:
    <Input type=password name=text2>
    <br>
    <Input type=button name=button2 value="Change">
    <br>
    </Form>
    <Script language="vbscr ipt">
    dim pass,a
    pass="rajeev"
    Sub button1_Onclick ()
    if (Form1.text1.va lue=pass)then
    msgbox "Password Correct"
    else
    msgbox "Password Incorrect"
    endif
    End Sub

    Sub button2_OnClick ()
    if (Form1.text2.va lue<>pass)then
    msgbox "Password Changed"
    else
    msgbox "Invalid Password"
    endif
    End Sub
    </Script>
    </Body>
    </HTML>

    This code is not working.. I dont know what mistake i have done. Please help me in solving this problem.. Thanks in advance..

    Thanks,
    Vasuki
    Are you using Internet Explorer?

    You have written local vbscript here that will compile and execute on the browser of the user. IE is built to handle local vbscript, other browsers are not I think.

    Also you do not have any reference to your events on your form controls.

    You need to use either onclick on your button control or onsubmit on the form tag control.

    [code=html]
    <Input type=button name=button1 value="Check" onclick="MySub" >
    [/code]

    If you are talking about build an classic ASP page that executes on a server however vbscript will work but it will not be event driven like you have here. Only javascript will handle local events that return msg boxes across multiple browsers.

    If you need to use VB to handle your data and events you will need to do it by submitting the form back to a .asp page on the server to handle your validations.

    [code=html]
    <form name="form1" method="post" action="MyHandl ePage.asp">
    [/code]

    The action page will be requested when the user clicks a submit button.

    From there you can get values from the text boxes with the request.form syntax.

    [code=asp]
    dim MyVar
    MyVar = request.form("t ext1")
    if MyVar = Pass then
    'correct password
    end if
    [/code]

    To understand form submission for ASP and VB better you should go here.
    W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

    Comment

    Working...