CodeTalk
CodeTalk

Reputation: 3667

Implement SHA 512 Hash with Code Igniter

I have a controller: landingpage.php

<?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]');
    }
}

I wondered how I can implement SHA 512 hashing like I had before when I was doing my app procedurally, exept this time in CODEIGNITER??

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

Does code igniter have a built in function for this??? or something similar?

Upvotes: 2

Views: 4955

Answers (1)

No Results Found
No Results Found

Reputation: 102854

Does code igniter have a built in function for this?

No, but since PHP does - you don't need one.

hash('sha512', $string);

It can't get much easier or shorter than that. Why rewrite existing functionality?

However, for hashing passwords in PHP I suggest phpass:

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

Upvotes: 5

Related Questions