PDA

View Full Version : Document Write instead of Alert



Rockonmetal
05-09-2007, 05:23 PM
I found this script off of someother site... here it is:

function had(){
loggedin=false;
username="";
password="";
username=prompt("Username:","");
username=username.toLowerCase();
password=prompt("Password:","");
password=password.toLowerCase();
if (username=="1" && password=="1") {
loggedin=true;
window.location="home.html";
}
if (username=="Username" && password=="Password") {
loggedin=true;
window.location="home.html";
}
if (loggedin==false) {
alert("Hi");
}
}
this is js file. I want the alerts and window.locations to change to document.writes. cuz I want it to say... "Correct" or "Incorrect"... I DON'T WANT TO CHANGE PAGES!

thanks all

thetestingsite
05-09-2007, 05:28 PM
Not tested, and not sure if this is what you mean, but here you go.



function had(){
loggedin=false;
username="";
password="";
username=prompt("Username:","");
username=username.toLowerCase();
password=prompt("Password:","");
password=password.toLowerCase();

if (username=="1" && password=="1") {
loggedin=true;
document.write('Correct');
}

if (username=="Username" && password=="Password") {
loggedin=true;
document.write('Correct');
}

if (loggedin==false) {
document.write('Incorrect');
}

}

Twey
05-09-2007, 06:09 PM
You are aware that this provides no security whatsoever, correct?

Using document.write() might also break your page, depending on how and where the had() function is called.

Rockonmetal
05-09-2007, 06:18 PM
I no, its a small scale website, thats going to be encrypted, yada yada...

Rockonmetal
05-09-2007, 06:23 PM
The testing site, hey, this thing isn't working, twedy u said about something about placement... where might it work. this is going into a form.

Twey
05-09-2007, 06:54 PM
I no, its a small scale website, thats going to be encrypted, yada yada...Still doesn't provide any protection unless you involve something server-side, even if it's just URL obfuscation (see here (http://www.twey.co.uk/?q=encpass) for an example).

Rockonmetal
05-09-2007, 07:03 PM
Oh i got it to sorta work, but i sorta want it 2 make the document write on the same page, not a different page... lol