Problems with an infinite loop - javascript

I am doing a login for a page, if I enter index.html it has to redirect me to the login, html.
the issue here is that I am getting an infinite loop and I don't know what my syntax error is, I would appreciate your help!
This is where the error is:
sessionStorage.setItem('usuario',false)
var usuario = sessionStorage.getItem(usuario)
var logueate = window.location.replace('login.html')
if (!sessionStorage.getItem('usuario')) {
logueate;}
my login JS code
function validacion(){
var email = document.getElementById("email").value;
var password = document.getElementById("password").value;
if (email == "" ) {
document.getElementById("errores").innerHTML = "Campos invalidos";
} else if (password == "") {
document.getElementById("errores").innerHTML = "Campos invalidos";
}
else { window.location.href="index.html"

Does your login.html is alos executing this code, if yes then it is redirecting again and again to login.html page.

Related

how can i make the tab close upon user opening inspect element? or can i store passwords somewhere that users cant access?

So I am making a website with logins that you need to contact me to obtain (to avoid spam bots and stuff) however I do not know how to hide the passwords, here is a code of all JavaScript I use for the site:
//specials
const enabledUsers = ['adminAccount', 'POGDUCKIE']
const unc = "adminAccount"
const pwc = "TEST"
const unc2 = "POGDUCKIE"
const pwc2 = "TEST"
const unc3 = "fierytech"
const pwc3 = "TEST"
const member = ['POGDUCKIE']
const partner = ['none yet']
const admin = ['adminAccount']
const owner = ['fierytech']
var user = document.getElementById("user")
function redirectAddAurasouls(){
document.write("Here is the bot invite link: <a href=https://discord.com/api/oauth2/authorize?client_id=944639749195448320&permissions=8&scope=bot>https://discord.com/api/oauth2/authorize?client_id=944639749195448320&permissions=8&scope=bot</a>. Thank you for adding aurasouls!<br><br><button onclick=location.reload()>Go Back</button>")
}
function redirectDiscordInvite(){
document.write("The Discord Support Server Invite Link Is: <a target=blank_ href=https://discord.gg/khR9DFNqs6>https://discord.gg/khR9DFNqs6</a><br><button onclick=location.reload()>Go Back</button>");
}
function redirectStaff(){
document.getElementById("passwordTable").style.display = "none";
}
function passwordCheck(){
var pw = document.getElementById("Password").value;
var un = document.getElementById("Username").value;
if(un == unc) {
if(pw == pwc){
redirectStaff()
user.innerHTML = "adminAccount"
}
else{
document.getElementById("passwordStatus").innerHTML = "Incorrect Password. Please try again.";
}
}
else{
if(un == unc2) {
if(pw == pwc2){
redirectStaff()
user.innerHTML = "POGDUCKIE"
}
else{
document.getElementById("passwordStatus").innerHTML = "Incorrect Password. Please try again.";
}
}
else{
document.getElementById("passwordStatus").innerHTML = "Incorrect Username. Please contact FieryTech on discord to get a free login.";
}
}
}
//the code below stops user from opening console
document.onkeydown = function(e) {
if(event.keyCode == 123) {
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode == 'I'.charCodeAt(0)) {
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode == 'C'.charCodeAt(0)) {
return false;
}
if(e.ctrlKey && e.shiftKey && e.keyCode == 'J'.charCodeAt(0)) {
return false;
}
if(e.ctrlKey && e.keyCode == 'U'.charCodeAt(0)) {
return false;
}
}
As you can see, the JS file has something to prevent users opening console with keybinds, but the user can still access inspect element in other ways. Is there a way I can externally store the data so only the javascript code can access it so users can't steal logins? If there is any way possible to hide these logins please let me know.
Thanks
P.S. before you say that some of the JS doesn't work, I stopped working on the login until I find a way to properly store logins.
The only marginally secure way to store passwords in code that runs on the client is to hash them yourself first, send the hashes, and then to perform hashing on the user passwords when they're submitted. Possible, but convoluted and still not all that secure.
The only good way to do something like you're trying to do is to store the passwords on the server only. Don't ever send the data to the client. Any data sent to the client can be easily read and reverse-engineered by the client.
When the user submits a password, make a request to your server with the password. On the server, hash the password that the client sent, and then look up in your database of users whether the username and password hash match. If so, let them in (with all the appropriate privileges) - if not, tell them that their credentials were incorrect.

Form validation of email id and password using Javascript

Code
I cannot understand what is going wrong with this code?
I need to validate emailid and password for the website I am making using Javascript.
The first alert is working properly as well as the alert in else,
only if's lert is not coming.
alert("hi")
const loginForm = document.getElementById("logform");
const loginButton = document.getElementById("logbut");
const emailid = loginForm.emailid.value;
const password = loginForm.password.value;
loginButton.addEventListener("click", function() {
if (emailid === "user#123" && password === "user") {
alert("You have successfully logged in.");
}else{
alert("oh");
}
});

How to change page with JS in html?

I want when the user successfully sign up it goes to the main page.
I already tried a lot of function but it doesn't work..
code :
var nama = document.getElementById("name");
var email = document.getElementById("email");
var userPw = document.getElementById("pass");
sign up code :
function store(){
var rePass = document.getElementById("re_pass");
if (userPw.value == rePass.value && nama.value != "") {
alert("Berhasil daftar!");
} else {
alert('Coba periksa lagi~');
return;
}
localStorage.setItem('namaUser', nama.value);
localStorage.setItem('emailUser', email.value);
localStorage.setItem('passwordUser', userPw.value);
i tried this function also :
self.location = 'sign in.html';
}
Try this one. make sure to clear the space between in this segment!!! 'sign in.html'
window.location = 'sign in.html'
Try this.
window.location.replace("/");
or
window.location.href = "/";

How to instantly redirect the user to a new page via router when the user logs in succesfully(password, username are correct)

Via vue.js I've made a login form with a username and password, and set conditions for them. When the user submits the correct username and password I want to redirect them to a new page vie the vue.js Router. So for example if the user is currently located in "localhost8080/", after a successful login I want to immediately send them to "localhost8080/#/profile"
validate() {
var email = document.getElementById("email").value;
var atSign = email.indexOf("#");
var error = document.getElementById("error");
var mistakes = "";
var hasErrors = false;
if (this.newP != this.password){
mistakes += "Entered password is incorrect. ";
hasErrors = true;
}
if (atSign === -1) {
mistakes += "The email is missing an '#' sign.";
hasErrors = true;
}
// console.log(this.newP.length)
if (hasErrors === true) {
error.innerHTML = mistakes;
return false;
} else {
alert("Login confirmed");
return true;
//I realize it's supposed to be here, but I do not know
//how to write it.
}
}
If You using vue-router, better to use programmatic navigation.
Link: https://router.vuejs.org/guide/essentials/navigation.html
if(loginConfirmed) {
this.$router.push({ path: 'dashboard' });
}

javascript problems when another javascript added

I have the following script that works fine until I add the other javascript below...
First Script in the header tags
function validateForm() {
var valid = true;
var errMsg = "";
var email = document.emailform.email.value;
var filter = /^([a-zA-Z0-9_.-])+#(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
if(email.length <= 0) {
valid = false;
errMsg += "Email address is required.\n";
} else {
if (!filter.test(email)) {
valid = false;
errMsg += "Please provide a valid email address.\n";
}
}
if (errMsg.length > 0) {
alert(errMsg);
return false;
}
}
and just before the closing tags I have...
$('#form').submit(validateForm);
The above works fine, except once I add the script below, validateForm no longer works. This following is added just before the closing body tags.
cbr202=Math.random()*10000000000000000;document.write('<scr'+'ipt language="JavaScript" src="http://example.com/landing.php?lpip=411&202cb='+cbr202+'" type="text/javascript"></scr' + 'ipt>');
I can't seem to figure out what's causing the issue. Hoping someone with experience can see the problem.
Solved: I figured it out... it was due to my own sloppiness. I should have the jquery event handler below the document.write script, not above it.
You forgot to add a closing } to the function. That caused an error and resulted in any JS coming after that to not execute.
function validateForm() {
var valid = true;
var errMsg = "";
var email = document.emailform.email.value;
var filter = /^([a-zA-Z0-9_.-])+#(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
if(email.length <= 0) {
valid = false;
errMsg += "Email address is required.\n";
} else {
if (!filter.test(email)) {
valid = false;
errMsg += "Please provide a valid email address.\n";
}
}
if (errMsg.length > 0) {
alert(errMsg);
return false;
}
}
the url generated by
src="http://mysite.com/landing.php?lpip=411&202cb='+cbr202
does not exist. The browser tries to load the script from the url using a get request and fails.
cbr202=Math.random()*10000000000000000;
I think you need change code same below
var cbr202=Math.random()*10000000000000000;

Categories