Cant Access Window.location.replace after IF ELSE in JAVASCRIPT - javascript

I try to replace my page , but it cant still replace.
i think that error from after IF and ELSE after i loged from console
but still cant resolve that.
help..
function LoginWithEmail(){
var email = curEmail.indexOf(emailLogin.value);
var password = curPass.indexOf(passLogin.value);
if(emailLogin.value === curEmail[email] && passLogin.value === curPass[password]){
return window.location.replace("admin-dashboard.php");
}else{
alert("Your email or password are empty or wrong!");
return false;
}
}

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.

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' });
}

Why won't JavaScript alert box work in this example?

I am trying to validate 3 fields in a html form using javascript. If any of the fields are empty an alert box appears with a message indicating which fields are empty. This all works fine. I'm having a problem getting the message (msg2) to appear in an alert box when the form has been completed properly. My code is below-I know it's just something simple that I'm missing if anyone can help. Thanks!
var valid = true;
var msg="Incomplete form:\n";
var msg2="Success! There are no null fields.";
if ( myname== "" ) {
msg+="You need to fill the name field!\n";
valid = false;
}
if ( emailaddress == "" ) {
msg+="You need to fill in your email!\n";
valid = false;
}
if ( commentString == "" ) {
msg+="You need to fill in your comment!\n";
valid = false;
}
if ((!myname=="")&&(!emailaddress=="")&&(!commentString=="")){
return msg2;
}
if (!valid) alert(msg);
return valid;
}
You're right, it's something simple: return msg2; will not open an alert box. You still have to call alert() somewhere.
i think a little change in your code will solve the problem:
if (!valid) alert(msg);
return valid;
}
change it to
if (!valid) {
alert(msg);
return valid;
}
if (!valid) {
alert(msg);
} else {
alert(msg2);
}
return valid
Maybe somethign like that? And remove the block with if ((!myname=="")&& ...

Javascript validation of login form - field must be not blank and contain a "\"

Here is the code I have now.
function ns_check()
{
var login = document.forms['vpnForm'].login.value;
var passwd = document.forms['vpnForm'].passwd.value;
var domainname = login.indexOf("\\")
if (domainname = - 1){
window.alert(_("You need to enter a domain name")); return false;
}
if (login == ""){
window.alert(_("You need to enter login name")); return false;
}
if (passwd == ""){
window.alert(_("You need to enter passwd")); return false;
}
return true;
}
When you do not use a backslash in the login box it does popup an alert window, but it is empty.
Any help would be appreciated.
if (domainname = - 1)
should be
if (domainname === - 1)

Validation of registration form with AJAX and JSON

I have a Username field in my registration form. When the user hits the Submit button, it should check if the username is not empty and that such username doesn't exist yet. So I have these functions:
function register() {
var userName = checkIsUsernameExist();
var passwordMatch = checkPasswordMatch();
if(userName && passwordMatch){
$.getJSON("inc/API.php",
{
command : "register",
username : $("#txtNewUsername").attr("value"),
password : $("#txtNewPassword").attr("value"),
email : $("#txtEmail").attr("value"),
phone : $("#txtPhone").attr("value")
},
function ()
{
$("#divIsRegFormValid").removeClass("registrationFormAlert");
$("#divIsRegFormValid").addClass("registrationFormConfirm");
$("#divIsRegFormValid").html("Thank you for registering!");
}
);
} else {
$("#divIsRegFormValid").removeClass("registrationFormConfirm");
$("#divIsRegFormValid").addClass("registrationFormAlert");
$("#divIsRegFormValid").html("Some errors occured. Please register again.");
}
}
function checkIsUsernameExist(){
if($("#txtNewUsername").attr("value") == "") {
$("#divIsUsernameExist").html("");
return false;
} else {
$.getJSON("inc/API.php",
{
command : 'isUsernameExist',
username : $("#txtNewUsername").attr("value")
}).done(
function(result)
{
if (result != true){
$("#divIsUsernameExist").removeClass("registrationFormAlert");
$("#divIsUsernameExist").addClass("registrationFormConfirm");
$("#divIsUsernameExist").html("This username is available!");
return true;
} else {
$("#divIsUsernameExist").removeClass("registrationFormConfirm");
$("#divIsUsernameExist").addClass("registrationFormAlert");
$("#divIsUsernameExist").html("This username is not available!");
return false;
}
});
}
}
At this moment I only receive False if the username is empty, and if it's not - I get Undefined (checked it with some Alert commands). So how can I make it work and return True or False if the username is entered and it's been checked if such username already exist or not?
Thank you!
.val() is prefered $("#txtEmail").attr("value") => $("#txtEmail").val() ;)
You get undefined probably because there is no value attribute in your html use $('#txtEmail').val() instead.

Categories