views:

59

answers:

2

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?

A: 

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');
});
Dalen
+8  A: 
$(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.

EMMERICH
exactly what i was going to say!! +1
Mouhannad
+1, this is huuge security problem! But yes, the answer should do what has been asked.
Tom
yups..this is for the starter..could you give me some script that you mention at no.2?
klox