2012-03-10 50 views
2

我有一個控制器:landingpage.php用代碼點火器實施SHA哈希512

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

class LandingPage extends CI_Controller { 

    public function index(){ 
      $data = array(
      'head' => $this->load->view('Landing_Header', '', true), 
      'guts' => $this->load->view('Landing_Guts', '', true), 
      'foot' => $this->load->view('Landing_Footer', '', true) 
     ); 
      $this->load->view('index', $data); 
    } 

    public function validateInput(){ 
     #load help libraries for use 
     $this->load->helper("form"); 
     $this->load->helper("form_validation"); 

     ///////////////////////////////////////////////////////////////// 
     /////////////////////// New User Validation ///////////////////// 
     /////////////////////// Format for Validation : //////////////// 
     ////////// "field name","Error Value","validation method" /////// 
     $this->form_validation->set_rules('fullname','Your Name','required|min_length[2]|max_length[20]'); 
     $this->form_validation->set_rules('email','Your Email','required|valid_email|is_unique[users.email]'); 
     $this->form_validation->set_rules('emailConf','Email Confirm','required|matches[email]'); 
     $this->form_validation->set_rules('password','Password','required|min_length[2]|max_length[20]'); 
    } 
} 

我不知道我怎麼能實現SHA哈希512像我,當我在程序上做我的應用程序有過,這exept在CODEIGNITER中的時間?

isset($_POST['password']) 
$dynamSalt = mt_rand(20,100); 
$userPassword = hash('sha512',$dynamSalt.$userPassword); 

是否代碼點火器有一個內置函數?或類似的東西?

回答

4

代碼點火器有一個內置的函數嗎?

不,但由於PHP的確如此 - 你不需要一個。

hash('sha512', $string); 

它不會變得更容易或更短。爲什麼要重寫現有的功能?

然而,在散列密碼,PHP,我建議phpass:

http://www.openwall.com/phpass/

+0

這是真的。感謝Madmartigan! – CodeTalk 2012-03-10 21:35:19

+0

我將如何使用代碼Igniters $ this-> form_validation'調用? – CodeTalk 2012-03-10 21:36:21

+0

隨着回調:http://codeigniter.com/user_guide/libraries/form_validation.html#callbacks – 2012-03-10 21:37:09