微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 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>

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

public function login(){
    $pass_word = $this->input->post('pass_word');
    die($pass_word);
}

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

>这是安全问题吗?
>任何人都可以通过wireshark等网络监控工具获取密码吗?

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

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

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

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

> http://sajjadhossain.com/2008/10/27/ssl-https-urls-and-codeigniter/
> http://nigel.mcbryde.com.au/2009/03/working-with-ssl-in-codeigniter/
> How can I have CodeIgniter load specific pages using SSL?

特别是强制ssl功能Nigel’s post

Create a file in application/helper called 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());
    }
}

Load the helper,then in the constructor for any controller that
requires ssl,simply insert:

force_ssl();

In every controller that you don’t want to have ssl put:

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐