cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript for validating the user before he tries to access a web page

Former Member
0 Kudos

Hi all,

I need a javascript to validate the user when tries to access an web page.

when the user gives the url , it should ask for the password and if it is valid, the page should be loaded else it should display a message like "u r not authorized to view this page ".

Regards,

Eben

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

<html>

<head>

<script language="javascript">

function check()

{

alert("enter user name and password");

}

function reload()

{

form.action="your page"

form.submit();

}

</script>

</head>

<body>

here you can write code for what you want and write select statement for picking data from database for valid person. if database fails to retrive data of a entered person, then you can write the following code here:

<script language="javascript">

alert("you are not authorized person, register you profile");

</script>

write the code on button like this

<input type="button" name="submit" onClick="check();reload()">

Do like this, you will get the result.

Regards,

Bhaskar

sridevi_p
Active Contributor
0 Kudos

Alerting the user to enter a password is possible using javscript

<html>

<head>

<script language="JavaScript:>

function alertForPwd() {

alert("Please enter valid password for entering the website");

}

</script>

</head>

<body onload="Javascript: alertForPwd();">

....

</body>

</html>

For checking whether the user entered password is correct is not possible with javascript alone. you either need have server side scripting.

Regards,

Sridevi

Note: Award points if found useful

gregorw
Active Contributor
0 Kudos

Hello Eben,

why must it be JavaScript? You can have Basic Auth, Cert Auth, etc.

Regards

Gregor

Former Member
0 Kudos

Hi Gregor,

Am not familiar with Basic Auth & Cert Auth. Can you give me some more details regarding this?

gregorw
Active Contributor
0 Kudos

Hello,

then please research first using a Search Engine like Google.

Regards

Gregor