2011-12-31 16 views
0

私のユーザサーバー側をphpで検証しようとしていて、致命的なエラーが表示されています:未定義の関数reGenPassHash()を/ home/xtremer/public_html/kowmanager/application/models /現在13行目のloggedin.phpに、reGenPassHash関数が自動的にロードされたモデルがあります。このメッセージが原因ではなく何らかの理由で使用できると思っていました。なぜ誰かが説明する?PHPで検証する

モデル:

public function check_login($username, $password) 
{ 
    $generated_password = reGenPassHash($password); 
    $query = "SELECT user_id WHERE username = ? AND password = ?"; 
    $result = $this->db->query($query, array($username, $generated_password)); 

    if ($result->num_rows == 1) 
    { 
     return $result->row(0)->user_id; 

    } 
    else 
    { 
     return false; 
    } 

} 

コントローラー:

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Usermanagement extends CI_Controller { 

public function __construct() 
{ 
    parent::__construct(); 
} 

public function index() 
{ 
    //Config Defaults Start 
    $msgBoxMsgs = array();//msgType = dl, info, warn, note, msg 
    $cssPageAddons = '';//If you have extra CSS for this view append it here 
    $jsPageAddons = '';//If you have extra JS for this view append it here 
    $metaAddons = '';//Sometimes there is a need for additional Meta Data such in the case of Facebook addon's 
    $siteTitle = '';//alter only if you need something other than the default for this view. 
    //Config Defaults Start 


    //examples of how to use the message box system (css not included). 
    //$msgBoxMsgs[] = array('msgType' => 'dl', 'theMsg' => 'This is a Blank Message Box...'); 

    /**********************************************************Your Coding Logic Here, Start*/ 

    if(!$this->session->userdata('logged_in')) 
    { 
     $bodyContent = "login";//which view file 
    } 
    else 
    { 
     $bodyContent = "cpanel/index";//which view file 
    } 

    $bodyType = "full";//type of template 

    /***********************************************************Your Coding Logic Here, End*/ 

    //Double checks if any default variables have been changed, Start. 
    //If msgBoxMsgs array has anything in it, if so displays it in view, else does nothing.  
    if(count($msgBoxMsgs) !== 0) 
    { 
     $msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs)); 
    } 
    else 
    { 
     $msgBoxes = array('display' => 'none'); 
    } 

    if($siteTitle == '') 
    { 
     $siteTitle = $this->metatags->SiteTitle(); //reads 
    } 

    //Double checks if any default variables have been changed, End. 

    $this->data['msgBoxes'] = $msgBoxes; 
    $this->data['cssPageAddons'] = $cssPageAddons;//if there is any additional CSS to add from above Variable this will send it to the view. 
    $this->data['jsPageAddons'] = $jsPageAddons;//if there is any addictional JS to add from the above variable this will send it to the view. 
    $this->data['metaAddons'] = $metaAddons;//if there is any addictional meta data to add from the above variable this will send it to the view. 
    $this->data['pageMetaTags'] = $this->metatags->MetaTags();//defaults can be changed via models/metatags.php 
    $this->data['siteTitle'] = $siteTitle;//defaults can be changed via models/metatags.php 
    $this->data['bodyType'] = $bodyType; 
    $this->data['bodyContent'] = $bodyContent; 
    $this->load->view('usermanagement/index', $this->data); 
} 

function login() 
{ 
    $this->form_validation->set_rules('username', 'Username', 'trim|required|max_length[50]|xss_clean'); 
    $this->form_validation->set_rules('password', 'Password', 'trim|required|max_length[12]|xss_clean'); 

    if ($this->form_validation->run() == FALSE) 
    { 
     $this->index(); 
    } 
    else 
    { 
     $username = $this->input->post('username'); 
     $password = $this->input->post('password'); 

     $user_id = $this->loggedin->check_login($username, $password); 

     if(! $user_id) 
     { 
      redirect('/'); 
     } 
     else 
     { 
      $this->session->set_userdata(array(
       'logged_in' => TRUE, 
       'user_id' => $user_id 
      )); 
      redirect('cpanel/index'); 
     } 
    } 
} 

function logout() 
{ 
    $this->session->sess_destroy(); 
    $this->index(); 
}  

} 

/* End of file usermanagement.php */ 
/* Location: ./application/controllers/usermanagement.php */ 

EDIT:

私は私のロジックが正しいことを確認しようとしています。代わりにコントローラのregenPassHash関数呼び出しを使用して作業する必要がありますか?

EDIT 2:

これは私のパスワード機能は、(getfuncモデル)どのように見えるかの例です:

<?php 
function GenPassHash($logPass) 
{ 
    $usersalt = substr(md5(uniqid(rand(), true)), 0, 11); 
    $encPass = sha1($logPass); 
    $sltPass = $encPass . $usersalt;$encSPass = sha1($sltPass); 
    $passArray = array($encSPass,$usersalt); 
    return $passArray; 
} 
function reGenPassHash($postDpass, $storeSalt) 
{ 
    $logPass = $postDpass; 
    $encPass = sha1($logPass); 
    $sltPass = $encPass . $storeSalt; 
    $encSPass = sha1($sltPass); 
    return $encSPass; 
} 

//useage 
$logPass = "catcher05";//this could be your posted variable from registration 

$passforDB = GenPassHash($logPass); 
echo "<pre>"; 
print_r($passforDB); 
echo "</pre>"; 
echo "Encrypted Password: " . $passforDB[0] . "<br />"; 
echo "Salted Value: " . $passforDB[1] . "<br />"; 

echo "----------------------------------<br />"; 
//in this example I post $passforDB[1] with the below function to stimulate having pulled it from a DB 
echo reGenPassHash($logPass, $passforDB[1]); //you would query based on your username being posted and only pull the salt and encrypted pass you would use the salt in this function 

?> 

コントローラー:

function login() 
{ 
    $this->form_validation->set_rules('username', 'Username', 'trim|required|max_length[50]|xss_clean'); 
    $this->form_validation->set_rules('password', 'Password', 'trim|required|max_length[12]|xss_clean'); 

    if ($this->form_validation->run() == FALSE) 
    { 
     $this->index(); 
    } 
    else 
    { 
     $username = $this->input->post('username'); 
     $password = $this->input->post('password'); 
     $generated_password = $this->getfunc->reGenPassHash($password); 

     $user_id = $this->loggedin->check_login($username, $password); 

     if(! $user_id) 
     { 
      redirect('/'); 
     } 
     else 
     { 
      $this->session->set_userdata(array(
       'logged_in' => TRUE, 
       'user_id' => $user_id 
      )); 
      redirect('cpanel/index'); 
     } 
    } 
} 

モデル:

public function check_login($username, $password) 
{ 
$query = "SELECT * WHERE username = ".$username.""; 
$result = $this->db->query($query); 

if ($result->num_rows == 1) 
{ 
    $passwordDB = $result->row(0)->password; 
    $passwordDB2 = $result->row(0)->password2; 


    return $result->row(0)->user_id; 

} 
else 
{ 
    return false; 
} 

} 
+0

reGenPassHash()関数があるモデルのコードを表示できますか? check_login関数の上にそのファイルを確実に含めていますか? –

+0

自動ロードされていないと、このモデルの上に含まれていることを意味しません。 –

答えて

1

オートローディングは、オブジェクトメソッドに対してのみ実行されます。あなたは、regen関数の呼び出しでオブジェクト表記を使用していないので、通常の関数呼び出しのように扱われています。この関数は定義されていません。あなたが好きなあなたのモデルオブジェクトを通して、あなたのreGenPassHash関数を呼び出す必要が

+0

このモデルの中の他のモデルから関数を呼び出すことはできますか? –

+0

あなたはそれが$ generate_password = $ this-> model-> getfunc-> reGenPassHash($ password)でなければならないと言っています。 $ generated_pa​​ssword = reGenPassHash($ password)の代わりに。 –

+0

投稿を編集してください。 –

1

$this->your_model_with_pass_function->reGenPassHash() 
+0

投稿を編集してください。 –

+0

あなたのコードは今編集したとおりに機能するはずですが、複数のコントローラが機能にアクセスする必要がある場合は、パスワード機能をモデルに移動するか、ライブラリに移動する必要があります。本当にあなたのモデルはライブラリです。ライブラリに移動してライブラリとして自動ロードするだけで、新しいコードが表示されるのと同じ方法で呼び出すことができます。それはまだ働いていないのですか? – davidethell

1

私はあなたのコードを見ただけでエラーが、あなたがあなたの方法間違った方法呼んでいるということです。どんなクラスメソッドでも、メソッドにアクセスするためのオブジェクトが必要です。

これは$ thisかもしれません。あなたのケースでは、または他の場合には他の何か。

は、それがモデルに依存しているとする場合にのみメソッドを呼び出すために$this -> reGenPassHash()を使用してみてくださいか、それぞれのオブジェクト修飾子が必要になります。

UPDATE:

  1. あなたのコントローラ上のごGenPassHash()& reGenPassHash()を含めます。代わり$this->getfunc->reGenPassHash()使用$this->reGenPassHash()
+0

投稿を編集してください。 –

+1

はい、論理的には、モデルにはデータベース関連のロジックのみが含まれている必要があります。 ....関数reGenPassHash()は、データベースとは独立したハッシュコードのみの開発に関連しています。そのため、コードはコントローラの代わりに配置する必要があります:) – Starx

+0

説明をありがとうございます。 –

3

reGenPassHash()関数の

  • はcheck_login()メソッドには見えません。そのオブジェクトでreGenPassHasを呼び出します。

    例:$object->reGenPassHas()

    これは範囲の問題です

  • +0

    投稿を編集してください。 –

    +1

    はい、データベースで再生されていないため、コントロールロボットに 'reGenPassHas()'を置くのがベストプラクティスです。あなたのメソッドがDBを使って作業する場合は、それらをモデルに移動するのがベストプラクティスです。 [モデルビューコントローラ](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) –

    +0

    マイポストをもう一度更新しました。 –