Exemple #1
0
 public static function attempt($array, $remember = false)
 {
     //Table::show(self::$hashedFields);
     //
     $hashed = array();
     //
     foreach ($array as $key => $value) {
         if (Table::contains(self::$hashedFields, $key)) {
             Table::add($hashed, Hash::make($array[$key]), $key);
         }
     }
     //
     //Table::show($hashed);
     //
     $where = "";
     $ok = false;
     //
     $i = 0;
     foreach ($array as $key => $value) {
         if ($i > 0) {
             $where .= " and ";
         }
         if (Table::contains(self::$hashedFields, $key)) {
             $where .= "{$key}='" . $hashed[$key] . "' ";
         } else {
             $where .= "{$key}='{$value}' ";
         }
         $i++;
     }
     $sql = "select * from " . self::$table . " where " . $where;
     //echo $sql;
     //
     if (Database::countS($sql) > 0) {
         //returning true value
         $ok = true;
         //
         // session
         $user = Database::read($sql);
         $saved = Config::get('auth.saved_fields');
         //
         $static = array();
         //
         foreach ($user[0] as $key => $value) {
             if (array_key_exists($key, $saved)) {
                 $static[$key] = $value;
             }
         }
         //
         Session::put('auths', $static);
         //
         // remember cookie
         if ($remember) {
             Cookie::create(Config::get('auth.rememeber_cookie'), $user[0]["rememberToken"], time() + 3600 * 24 * 7);
         }
     }
     //
     return $ok;
 }
Exemple #2
0
 public static function token()
 {
     $token_name = "#eyuD#BR@w";
     $token = "";
     //
     if (self::existe($token_name)) {
         $token = self::get($token_name);
     } else {
         $token = Hash::token();
         //
         self::put($token_name, $token);
     }
     return $token;
 }