2016-05-01 8 views
0

映画やテレビシリーズをダウンロードできる小さなウェブサイトを作成しました。私はユーザー登録とログインシステムを追加しました。私はxamppの最新バージョン(php version 5.6.19)を使ってウェブサイトをチェックしました。登録PHPファイルでは、私はパスワードの塩の技術を追加しました。 xamppで完全に機能しました。私は私のウェブサイトをホストした後、それは働かなかった。パスワード塩は生成されず、データベースに保存されます。しかし、ユーザー名、電子メール、パスワードはデータベースに正常に送信されます。私はウェブサイトをホストした後にパスワードの塩が働いていません

register.php

<?php 
require_once 'core/init.php'; 

if(Input::exists()){ 

     $user = new User(); 
     $salt = Hash::salt(32); 

     try{ 

      $user->create(array(
       'uname' => Input::get('uname'), 
       'mail' => Input::get('mail'), 
       'pass' => Hash::make(Input::get('pass'), $salt), 
       'salt' => $salt 

      )); 

      Session::flash('home', 'You have registered successfully now you can log in !'); 
      Redirect::to('index.html'); 

     }catch(Exception $e){ 
      die($e->getMessage()); 
     } 


} 

?> 

hash.php

<?php 
class Hash{ 
public static function make($string, $salt = ''){ 
    return hash('sha256', $string . $salt); 
} 

public static function salt($length){ 
    return mcrypt_create_iv($length); 

} 

public static function unique(){ 
    return self::make(uniqid()); 

} 
} 

user.php問題を引き起こす可能性が何

<?php 
class User{ 
private $_db, 
     $_data, 
     $_sessionName, 
     $_cookieName, 
     $_isLoggedIn; 

public function __construct($user = null){ 
    $this->_db = DB::getInstance(); 
    $this->_sessionName = Config::get('session/session_name'); 
    $this->_cookieName = Config::get('remember/cookie_name'); 

    if(!$user){ 
     if(Session::exists($this->_sessionName)){ 
      $user = Session::get($this->_sessionName); 

      if($this->find($user)){ 
       $this->_isLoggedIn = true; 
      }else{ 
       //process logout 
      } 
     } 
    }else{ 
     $this->find($user); 
    } 
} 


public function create($fields = array()){ 
    if(!$this->_db->insert('users', $fields)){ 
     throw new Exception('There was a problem creating an account !'); 
    } 
} 

public function find($user = null){ 
    if($user){ 
     $field = (is_numeric($user)) ? 'id' : 'uname'; 
     $data = $this->_db->get('users', array($field, '=', $user)); 
     if($data->count()){ 
      $this->_data = $data->first(); 
      return true; 
     } 
     return false; 
    } 
} 

public function login($username = null, $password = null, $remember = false){ 

    if(!$username && !$password && $this->exists()){ 
     Session::put($this->_sessionName, $this->data()->id); 
    }else{ 
    $user = $this->find($username); 

    if($user){ 
      if($this->data()->pass === Hash::make($password, $this->data()->salt)){ 
        Session::put($this->_sessionName, $this->data()->id); 
        if($remember){ 
         $hash = Hash::unique(); 
         $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id)); 

         if(!$hashCheck->count()){ 
          $this->_db->insert('users_session',array(
           'user_id' => $this->data()->id, 
           'hash' => $hash 

          )); 
         }else{ 
          $hash = $hashCheck->first()->hash; 
         } 

         Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry')); 
        } 
        return true;  
       } 
      } 
     } 

    return false; 
} 

public function exists(){ 
    return (!empty($this->_data)) ? true : false; 
} 

public function logout(){ 
    $this->_db->delete('users_session', array('user_id', '=', $this->data()->id)); 
    Session::delete($this->_sessionName); 
    Cookie::delete($this->_cookieName); 
} 

public function data(){ 
    return $this->_data; 
} 

public function isLoggedIn(){ 
    return $this->_isLoggedIn; 
} 
} 

...

+0

という表現は難しいです。 user.phpからコードを見ることはできますか? – winhowes

+0

"パスワード塩が生成されて保存されていません" --- 2つの異なる症状があります。それは生成され、保存されていませんか? 'register.php'の – zerkms

+0

にtry + catchブロック内にuser + saltのインスタンスがありますが、エラーメッセージはありますか?どのデータ型がデータベースのパスワードフィールドですか?それは値が渡されているよりも小さいことがあり、結果として保存されません。 – dchayka

答えて

1

チェックあなたのhash場合関数はWebホスト上のPHPインストールでサポートされています。
saltの機能でこれを試すことができます。bin2hex(mcrypt_create_iv(30, MCRYPT_DEV_RANDOM))

+0

はい。 PHPのバージョンは、Webホストでは5.6.19です – Kasun

+0

'エコー(mcrypt_create_iv(32))にしてください;'と私は結果を知っています。 – CodeWalker

+0

この結果である - !MXF + @ NJTp $Ǖ〜私は(アカウントを作成する問題が発生しました – Kasun

関連する問題