Codeigniter:如何在将表单提交给控制器之前加密密码?

Kan*_*iya 7 php security encryption passwords codeigniter

我有一个简单的html登录表单

<form method="post" action="http://www.example.com/login">
    <input type="text" name="text_box" />
    <input type="password" name="pass_word" />
    <input type="submit" name="submit">
</form>
Run Code Online (Sandbox Code Playgroud)

当我提交表格并在控制器中

public function login(){
    $pass_word = $this->input->post('pass_word');
    die($pass_word);
}
Run Code Online (Sandbox Code Playgroud)

这里的问题,它显示了普通密码,如果我输入123456控制器,我得到123456.

  1. 这是安全问题吗?
  2. 任何人都可以通过网络监控工具获取我的密码wireshark吗?

怎么避免这个?在发送到控制器之前,我可以在视图中加密密码吗?请提前帮助,谢谢.

jle*_*eft 13

如果您的帖子数据(密码等)被截获,那么它只会以明文形式显示.使用SSL/HTTPS将为您发送的数据提供加密.我不会依赖客户端JavaScript或任何类似的用于验证/登录用户的目的.看到正在使用安全连接,它也可能给您的用户更多信心.

首先,我刚刚阅读了有关SSL和HTTPS的一般信息,以及SSL证书 - Wiki,Google和SO都是很好看的地方,那里有很多信息.

对于使用带有CI的SSL/HTTPS,我发现这些有用:

特别是来自奈杰尔帖子的力量ssl功能:

在application/helper中创建一个名为ssl_helper.php的文件

if (!function_exists('force_ssl'))
{
    function force_ssl()
    {
        $CI =& get_instance();
        $CI->config->config['base_url'] =
                 str_replace('http://', 'https://',
                 $CI->config->config['base_url']);
        if ($_SERVER['SERVER_PORT'] != 443)
        {
            redirect($CI->uri->uri_string());
        }
    }
}

function remove_ssl()
{
    $CI =& get_instance();
    $CI->config->config['base_url'] =
                  str_replace('https://', 'http://',
                  $CI->config->config['base_url']);
    if ($_SERVER['SERVER_PORT'] != 80)
    {
        redirect($CI->uri->uri_string());
    }
}
Run Code Online (Sandbox Code Playgroud)

加载帮助器,然后在任何需要ssl的控制器的构造函数中,只需插入:

force_ssl();

在你不想让ssl放入的每个控制器中:

if (function_exists('force_ssl')) remove_ssl();

这是一种编程方法,另一种方法是使用.htaccess(如果你使用的是Apache).