title: php user login anf function
body: <pre><code>if(isset($_POST['login'])) {
  $username = mysql_real_escape_string($_POST['username']);
  $password = mysql_real_escape_string($_POST['password']);
  if(empty($username) || empty($password)) {
  $error = 1;
  $error_message = 'Please fill in all the required fields.';
  } else {
      get_login_name($username, $password);
      //The commented line works...
      //$query = mysql_query("SELECT /* user_logged true, page login */username, password FROM members WHERE username = '".$username."' AND password = '".sha1($password)."' LIMIT 1");
  }
  if(mysql_num_rows(get_login_name($username, $password)) == 0) {
      echo get_login_name($username, $password);
  $error = 1;
  $error_message = 'Incorrect username or password.';
  } elseif ($error == 0) {
  //Other stuff....
  }
  }
  </code></pre>
  
  <p>Function:</p>
  
  <pre><code>function get_login_name($password, $username) {
                  global $myDB;
                  global $config;
                  $query = "SELECT /* page == login, functions.php */username, password FROM members WHERE username = '".$username."' AND password = '".sha1($password)."' LIMIT 1";
                  $result = $myDB-&gt;Execute($query) or die(GetDbError($myDB-&gt;ErrorMsg()));
                  return $result;
  }
  </code></pre>
  
  <p>How properly check if username or password incorrect ? (part if(mysql_num_rows(g.....)
  In my opinion something wrong i have done ir function get_login_name with return and checking. By the way, using adodb.</p>
  
  <p>EDIT:
  After all i decided a bit test it, so, let's leave function as it now and let's check username and password  part:</p>
  
  <pre><code>if  (!is_null(get_login_name($password, $username))) {
      echo get_login_name($password, $username);
  $error = 1;
  $error_message = 'Incorrect username or password.';
  }
  </code></pre>
  
  <p>If username or password incorrect ir gives me:
  <strong>username,password</strong>   which mean result doesn't found at all (no user, if user correct gives same)</p>
  
  <p>Ok, let's enter valid user and pass, and it gaves:
  <strong>username,password zero,0a706ce75f3bc195c8ed7be5a21d3766abb0d384</strong></p>
  
  <p>What's wrong ?</p>