check value in if statement (javascript) from another html file - javascript

I am trying to make a page that contains a login form. I got its coding from a website (someone had given that), well in the coding the username and password is given for compare (which can be seen by anyone, who opens the html codes), that's why i want that how the value of username and password can be compared in java-script from an external txt file or html file.
Kindly see the coding in order to better understand my problem. In coding "ABC" and "123" are username and password.
<body>
<h1 style="font-family:Comic Sans Ms;text-align="center";font-size:20pt;
color:#00FF00;>
Simple Login Page
</h1>
<form name="login">
Username<input type="text" name="userid"/>
Password<input type="password" name="pswrd"/>
<input type="button" onClick="check(this.form)" value="Login"/>
<input type="reset" value="Cancel"/>
</form>
<script language="javascript">
function check(form)/*function to check userid & password*/
{
/*the following code checkes whether the entered userid and password are matching*/
if(form.userid.value = "ABC" && form.pswrd.value == "123")
{
window.open('target.html')/*opens the target page while Id & password matches*/
}
else
{
alert("Error Password or Username")/*displays error message*/
}
}
</script>
</body>

Technicly, you can load by AJAX a txt/xml or json file and read the data from that.
However, I strongly recommend that you make the user/password check on the server side as if you do it in javascript, it won't be secure at all as anyone could read them in less than 5 seconds !!!

Related

Password is visible in inspect element

i made a script that is basicly just a form where you have to put in a password to go to the admin page. when i was doublechecking everything i noticed that can see the script including the password with inspect element. Im still learning php, javascript, html and css and i cant figure out how to put that password in a seperate .js file and link it back to my password code.
This is the code i wrote. i was hoping if someone could learn me how to store the password in a seperate file and link it back
<h3>admin<h3>
<form>
<label for="pswd">Enter your password: </label>
<input type="password" id="pswd">
<input type="button" value="Submit" onclick="checkPswd();" />
</form>
<!--Function to check password the already set password is Kra5313-->
<script type="text/javascript">
function checkPswd() {
var confirmPassword = "kra5313";
var password = document.getElementById("pswd").value;
if (password == confirmPassword) {
window.location="/admin/Stored Ips.php";
}
else{
window.location="/sub pages/you_tried.php";
}
}
</script>
Everything inside the script tags is client-side, and the user will see it. That is why there is a backend and a database. To hide things from the user.

How do I get my code to accept more than one username and password?

I have a website that I "programmed" with HTML, and I found a script (JavaScript) to get a password for when the site is under maintenance. It currently only accepts a single username and password, is it possible to make it accept more than one? This is not my code, I found it online and want to add to it. This project is purely for educational purposes.
**Side note, I don't have a ton of experience, and people just down voting the question is not going to help me learn how to do this. I am a student in high school still learning these languages and the only way to learn is to get help when I need it.
<form name="login">
Username <input type="text" name="userid" />
Password <input type="password" name="pswrd" />
<input type="button" onclick="check(this.form)" value="Login" />
<button formaction="/index.html">Cancel</button>
</form>
<script language="javascript">
function check(form)/*function to check userid & password*/
{
/*the following code checkes whether the entered userid and password are matching*/
if(form.userid.value == "example-username" && form.pswrd.value == "example-password")
{
window.open("/mainpage.html")/*opens the target page while Id & password matches*/
}
else
{
alert("Error Password or Username")/*displays error message*/
}
}
</script>
Take a look at this link: [If Statements][1]
[1]: https://www.w3schools.com/js/js_comparisons.asp under the logical operators section. You will need to apply that logic to the following line
if(form.userid.value == "example-username" && form.pswrd.value == "example-password")
basically, duplicate the condition after the logic operator for a second person
if(form.userid.value == "example-username" && form.pswrd.value == "example-password" || form.userid.value == "example-username2" && form.pswrd.value == "example-password2")
as Chris Stated, this is by no means secure and would require a backend system and database to handle login checks. In this format anyone could simply view the JS code and obtain the password or, in the url, type the www.example.com/mainpage.html to completely bypass your login.

Automate Login To Zimbra Server

I am making a webpage that has a login functionality in it say www.newpage.com.
Below is the code of the page for reference.
<form name="login">
Username<input type="text" name="userid"/>
Password<input type="password" name="pswrd"/>
<input type="button" onclick="check(this.form)" value="Login"/>
<input type="reset" value="Cancel"/>
</form>
<script language="javascript">
function check(form)
{
if(form.userid.value == "user" && form.pswrd.value == "password")
{
window.open('file:///C:/Users/target.html', "_self")
window.open('https://webmail.sas.rutgers.edu/')
}
alert("Error Password or Username")
}
}
Now what I want is after i have logged in to this webpage it should automatically login to my local Zimbra server. The look and feel of zimbra server is like this : https://webmail.sas.rutgers.edu/
I am learning Javascript so not sure what is the way of doing it.
I read that it can be done by:
1) iframes (again don't know much about them)
2) cookies
Is there a way to do it more conveniently, preferring to do in Javascript. I am stuck with some important project please help.
The question is too broad and is not easy to be answered in short. But let's say you want to login into one particular existing mailbox/account, then one of the easiest ways to do it is to use the zimbra's preauth service and once you log's in your site you could redirect to that service url with specific request parameters which in turn creates and verifies a preauth key and redirects you to your mailbox. Of course you need to configure the preauth properly first. Here is the official guide for it https://wiki.zimbra.com/wiki/Preauth

How to validate User name Password using JS and HTML

I am trying to build a simple login form with the predefined username and Password and I want to validate user input matches with username & password that I specified.
If the user enters wrong username or password I want to display an alert message. I tried to write possible conditions, but I am not getting the alert message even I entered the wrong password.
I am new to development and need your support to learn this.
<!DOCTYPE html>
<html>
<head>
<title> javascript-validataion </title>
<link rel="stylesheet" href="java.css" type="text/css">
<script type="text/javascipt">
function check_info()
{
var username=document.getElementById("username").value;
var password=document.getElementById("password").value;
if(username == "user1" && password == "123456")
{
alert("Login Successful");
return false;
}
else
{
alert("checkpassword");
}
}
</script>
</head>
<body>
<form action="submission.html" method="post" onclick="return
check_info()";>
username:<input type="text" name="username" id="username" /><br>
</br>
password:<input type="text" name="password" id="password"/><br>
</br>
<input type="button" value="login" id="loginbtn"/>
</form>
</body>
</html>
You have 2 problems in provided example:
Typo in <script type="text/javascipt"> it should be <script type="text/javascript">
Use onclick in button <input type="button" value="login" id="loginbtn" onclick="return check_info()"/>
You cannot do this only with JS. You have to build a server side (e.g. with PHP or C#) page for querying the typed username using AJAX and then check the response. Also, you have to check the username existance on the confirmation before you update the new racord to the database for security reasons.
I suggest you to learn about AJAX and JQuery. If you are new, I suggest you to write simpler pages (e.g. a calculator or rock-paper-scissors game) for practise.

Writing simple single field javascript login form

Hello I need help with a simple JavaScript log in form. I am building a small website for me and my classmates. I want it to be able to redirect each user to a specific page when a corresponding passcode is entered.
I know it is unsafe but we don't plan on keeping valuable information on the site. I don't know about MSQL and don't even wish to use it. The code works at this level but am unable to add users since I don't understand JavaScript. Thanks in advance.
/*here is the code i got so far*/
<title>
Enter Passcode to proceed
</title>
<h1 style="font-family:Comic Sans Ms; text-align="center"; font-size:20pt; color:#00FF00;>
</h1>
<form name="login">
Passcode: <input type="text" name="userid"/>
<input type="button" onclick="check(this.form)" value="Login"/>
<input type="reset" value="Cancel"/>
</form>
<script language="javascript">
function check(form)/*function to check userid */
{
/*the following code checkes whether the entered userid is correct*/
if(form.userid.value == "JohnDoe")
{
window.open("johndoe.php")/*opens the target page while Id */
}
else
{
alert("Invalid Passcode, please try again!")/*displays error message*/
}
}
</script>
Here is your current if condition that contains a search for a user. Your else condition tells the user the passcode was invalid. Between them add some else if's. Also, boo for comic sans and also there are quite a few more methods that would work. You could, for example, post the form to a server-side script with hardcoded users there, and the viewer wouldn't be able to view source to get the info.
if(form.userid.value == "JohnDoe")
{
window.open("johndoe.php")/*opens the target page while Id */
}

Categories

Resources