0

hey all.. i want to make a simple login page. I have prepared two textfield.

<input type="text" id="user">
<input type="password" id="password">
<input type="button" id="go">

i want after click #go script can check:

if #user value != "admin" 
then #password value != "qaubuntu"

will show and JS alert. but if data same, will show some hidden . can you show me how to do that?

asked Oct 20, 2010 at 7:22
1
  • 1
    So i'll start my comment with the last two words you ended your answer with: Please help - me understand what you actually want. Oh, in proper English. Use Google Translate for all we care. Commented Oct 20, 2010 at 7:27

2 Answers 2

8
$(function() {
 $('#go').click(function() {
 if($('#user').val() !== "admin" || $('#password').val() !== "qaubuntu") {
 alert('Invalid login');
 return false;
 } else {
 return true;
 }
 });
});

that's the quick fix (assuming you're just playing around). But you should never do it like this for a few reasons:

  1. Anyone with half a brain can look at your JavaScript and see what the id/pw is
  2. I always think it's better to do the user authentication at the server side
  3. Probably a million others, it's so insecure it hurts

but for the purpose of this answer I'm assuming you're just practising with jQ.

answered Oct 20, 2010 at 7:27
Sign up to request clarification or add additional context in comments.

2 Comments

+1, this is huuge security problem! But yes, the answer should do what has been asked.
yups..this is for the starter..could you give me some script that you mention at no.2?
0

this is in jquery, when clicking on button #go check the login data

$('#go').bind('click',function()
{
 if($('#user').val() == 'admin' && $('#password').val() == 'qaubuntu'))
 //ok do what you need
 else
 alert('username or password not valid');
});
answered Oct 20, 2010 at 7:27

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.