2017-05-08 9 views
0

私はMVCの新機能です。 remember_tokenの関数がlaravelに書かれている場所は誰にでも分かりますか? 私はBluprintに見て、この機能が見つかりました:remember_tokenはlaravelによって自動的に生成されますか? codeigniterで同じことをすることはできますか?

public function rememberToken() 
{ 
    return $this->string('remember_token', 100)->nullable(); 
} 

だけデータベース内のフィールドを定義するための機能です。私はまた、契約/認証/ Authenticable.phpで見てきたが、ここにも、私はgetremembertokenと一緒に定義されたインターフェイスの束を見つけたとしてsetremembertoken:

実際の機能は、データベースに保存されたトークンを生成するために書かれている ​​

?誰も私を教えてくれますか?そして、私はcodeigniterで同様の関数を実装できますか?

+0

まず、OO PHPのインターフェイス、特性、継承、抽象化についてお読みください。あなたはコンセプトにもっと慣れてくるでしょう。 – Tpojka

+0

[ResetsPasswords](https://github.com/laravel/framework/blob/5.3/src/Illuminate/Foundation/Auth/ResetsPasswords.php#L105)の特性は、60文字のランダムな文字列を生成するようです。ユーザーは、データベースに格納されているトークンと一致するCookieを持ち、長いランダムな文字列のため、他のユーザーはそれが何であるかを推測できません。 – apokryfos

+0

@apokryfosええ、functiuonがデータベースにremember_tokenを保存していますか? –

答えて

1

LaravelのRememberトークンは、必要なときに作成されます。ユーザーが「私を覚えている」ボタンを登録してクリックすると、デフォルトのガードは「試み」方法(2つのパラメータを受け入れ

protected function attemptLogin(Request $request) 
{ 
    return $this->guard()->attempt(
     $this->credentials($request), $request->has('remember') 
    ); 
} 

しかし、実際のガードインタフェースは、実際には全く存在して試行方法を必要としない:そのとき、デフォルトの足場はAuthenticatesUsers::attemptLogin方法に呼び出すことですこれはすべてデフォルトのLaravelスキャフォールディングです)。

public function attempt(array $credentials = [], $remember = false) 
{ 
    $this->fireAttemptEvent($credentials, $remember); 
    $this->lastAttempted = $user = $this->provider->retrieveByCredentials($credentials); 

    if ($this->hasValidCredentials($user, $credentials)) { 
     $this->login($user, $remember); 
     return true; 
    } 

    $this->fireFailedEvent($user, $credentials); 
    return false; 
} 

順番にlogin(ガードインタフェースだけlaravel足場の再一部ではない)を呼び出し:

SessionGuardは、次の試行方法があります。 (おそらく暗号化された)クッキーにトークンを覚えて保存し、自動的にログインするためにそれを使用するためにおそらく

protected function queueRecallerCookie(AuthenticatableContract $user) 
{ 
    $this->getCookieJar()->queue($this->createRecaller(
     $user->getAuthIdentifier().'|'.$user->getRememberToken() 
    )); 
} 

:によって

protected function cycleRememberToken(AuthenticatableContract $user) 
{ 
    $user->setRememberToken($token = Str::random(60)); 
    $this->provider->updateRememberToken($user, $token); 
} 

続く:あなたが呼び出しシーケンス以下に保つなら、それはちょうどつまるところユーザーは後で

Laravelはオープンソースであることを指摘しておきます。ソースコードを実行するこのプロセス全体は、実装の詳細が必要なときはいつでも自分で行うことができます。

1

はいあなたはまた、CodeIgniterの中でこれを行うことができます

あなたはセキュリティ上のクラスを経由してCSRFトークン名と値を取得することができ、あなたのapplication/config/config.php

// Default $config['csrf_protection'] = FALSE; change and set TRUE 

$config['csrf_protection'] = FALSE; 
// Change it To 
$config['csrf_protection'] = TRUE; 

$config['csrf_token_name'] = 'csrf_token'; // The token name 
$config['csrf_cookie_name'] = 'csrf_cookie_name'; // The cookie name 
$config['csrf_expire'] = 7200; // The number in seconds the token should expire. 
$config['csrf_regenerate'] = FALSE; // Regenerate token on every submission 
$config['csrf_exclude_uris'] = array(); // Array of URIs which ignore CSRF checks 

を開きます。

$this->security->get_csrf_hash(); 
$this->security->get_csrf_token_name(); 

この機能は、system/core/Security.phpの行にあります306, 319

関連する問題