Php 密码功能不允许访问
我正在使用CodeIgniter-2014年4月12日的最新版本 我正在尝试将密码功能写入我的网站,用于公司登录门户。门户还没有编写,只是功能而已。它会显示,不会给我任何错误,除了无效密码的错误。我不知道问题出在哪里。因此,我包括所有适用的资源 更新!我发现了问题所在,现在我只需要知道如何以正确的方式解决它。在我的型号上,我使用MD5加密了密码。在运行探查器并看到从数据库或应用程序生成并发送加密密码后,我关闭了该功能,我不确定。无论如何,在那之后,密码让我通过,并在需要时拒绝访问。我如何保存加密 --模型-- 公司/用户Php 密码功能不允许访问,php,codeigniter,passwords,Php,Codeigniter,Passwords,我正在使用CodeIgniter-2014年4月12日的最新版本 我正在尝试将密码功能写入我的网站,用于公司登录门户。门户还没有编写,只是功能而已。它会显示,不会给我任何错误,除了无效密码的错误。我不知道问题出在哪里。因此,我包括所有适用的资源 更新!我发现了问题所在,现在我只需要知道如何以正确的方式解决它。在我的型号上,我使用MD5加密了密码。在运行探查器并看到从数据库或应用程序生成并发送加密密码后,我关闭了该功能,我不确定。无论如何,在那之后,密码让我通过,并在需要时拒绝访问。我如何保存加密
<?php
class Company_user extends CI_Model {
function login($username, $password){
$this->db->select('company_user_id, username, password');
$this->db->from('company_user');
$this->db->where('username', $username);
$this->db->where('password', MD5($password));
$this->db->limit(1);
$query = $this->db->get();
if($query->num_rows() == 1) {
return $query->result();
} else {
return FALSE;
}
--控制器--
登录
维菲洛金
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Verifylogin extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('company_user', '', TRUE);
}
function index() {
//This method will have the credentials validation
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
if ($this->form_validation->run() == FALSE) {
//Field validation failed. User redirected to login page
$title = 'ImpactU Online';
$subtitle = 'Company Login';
$subhead = 'Login Below.';
$attributes = array(
'class' => 'pure-form pure-form-stacked alert alert-info',
);
$this->load->view('template/header', array(
'title' => $title,
'subtitle' => $subtitle,
'subhead' => $subhead,
));
$this->load->view('login_view', array(
'attributes' => $attributes,
));
$this->load->view('submit');
$this->load->view('template/footer');
} else {
//Go to private area
redirect('company_home', 'refresh');
}
}
function check_database($password) {
//Field validation succeeded. Validate against database
$username = $this->input->post('username');
//query the database
$result = $this->company_user->login($username, $password);
if ($result) {
$sess_array = array();
foreach ($result as $row) {
$sess_array = array(
'id' => $row->id,
'username' => $row->username
);
$this->session->set_userdata('logged_in', $sess_array);
}
return TRUE;
} else {
$this->form_validation->set_message('check_database', 'Invalid username or password');
return false;
}
}
}
家公司
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class Company_home extends CI_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$title = 'ImpactU Online';
$subtitle = 'Welcome To the Company Portal';
$subhead = 'Please Select an Option';
$this->load->view('template/header', array(
'title' => $title,
'subtitle' => $subtitle,
'subhead' => $subhead,
));
$data['username'] = $session_data['username'];
$this->load->view('company_home_view', $data);
$this->load->view('template/footer');
}
else
{
//If no session, redirect to login page
redirect('login', 'refresh');
}
}
function logout()
{
$this->session->unset_userdata('logged_in');
session_destroy();
redirect('company_home', 'refresh');
}
}
--观点--
模板/标题
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title><?php echo html_escape($title); ?></title>
<link rel="shortcut icon" href="<?php echo base_url("assets/images/favicon.ico"); ?>" type="image/x-icon">
<link rel="icon" href="<?php echo base_url("assets/images/favicon.ico"); ?>" type="image/x-icon">
<link
href="<?php
echo base_url('assets/css/impactU.css');
?>" rel="stylesheet" type="text/css"
/>
<link
href="<?php
echo base_url('assets/font-awesome-4.2.0/css/font-awesome.min.css');
?>" rel="stylesheet" type="text/css"
/>
<link
href="<?php
echo base_url('assets/bootstrap/css/bootstrap.min.css');
?>" rel="stylesheet" type="text/css"
/>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.5.0/pure-min.css">
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.5.0/grids-responsive-min.css">
<link
href="<?php
echo base_url('assets/css/side-menu.css');
?>" rel="stylesheet" type="text/css"
/>
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-57039794-1', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<div id="layout">
<!-- Menu toggle -->
<a href="#menu" id="menuLink" class="menu-link">
<!-- Hamburger icon -->
<span></span>
</a>
<div id="menu">
<div class="pure-menu pure-menu-open">
<a class="pure-menu-heading" href="<?php echo site_url(); ?>">ImpactU</a>
<ul>
<li><a href="<?php echo site_url(); ?>">
<i class="fa fa-home"></i>
Home
</a>
</li>
<li><a href="<?php echo base_url('index.php/blog'); ?>">
<i class="fa fa-rss"></i>
Blog
</a>
</li>
<li><a href="<?php echo base_url('index.php/store'); ?>">
<i class="fa fa-money"></i>
Store
</a>
</li>
<li><a href="<?php echo base_url('index.php/contact'); ?>">
<i class="fa fa-envelope"></i>
Contact
</a>
</li>
<li><a href="<?php echo base_url('index.php/about'); ?>">
<i class="fa fa-exclamation-circle"></i>
About
</a>
</li>
<li class="menu-item-divided"><a href="<?php echo base_url('index.php/login'); ?>">
<i class="fa fa-lock"></i>
Company Login
</a>
</li>
<li class="menu-item-divided"><a href="<?php echo base_url('index.php/paypal'); ?>">
<i class="fa fa-paypal"></i>
Paypal Demo
</a>
</li>
</ul>
</div>
</div>
<div id="main">
<div class="header">
<h1><?php echo html_escape($title); ?></h1>
<h2><?php echo html_escape($subtitle); ?></h2>
</div>
<div class="content">
<h2 class="content-subhead"><?php echo html_escape($subhead); ?></h2>
模板/页脚
<hr/>
<div class="footer">
<p><i class="fa fa-copyright"></i> 2014 Tyler Lazenby</p>
</div>
</div>
</div>
</div>
<script src="<?php $this->load->helper('url');
echo base_url('assets/js/ui.js'); ?>">
</script>
</body>
</html>
登录视图
<?php echo validation_errors(); ?>
<?php echo form_open('c=verifylogin', $attributes); ?>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-3">
<label for="username">Username</label>
<input id="username" type="text" name="username" placeholder="username" value="<?php echo set_value('username'); ?>" required/>
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for = "password">Password</label>
<input id="password" type="password" name="password" required/>
</div>
</div>
提交
<legend>Click submit when done</legend>
<div>
<button type="submit" class="pure-button pure-button-primary">
<i class="fa fa-thumbs-o-up"></i>
Submit
</button>
</form>
</div>
公司主页视图
<h2 class="content-subhead">Welcome <?php echo $username; ?>!</h2>
<a href="home/logout">Logout</a>
非常感谢您的帮助。非常简单,只需将加密从模型中删除。我已经发现一个错误,您可能会发现,但它不是解决方案;id应为Verifylogin控制器第55行的计算机用户id。
<h2 class="content-subhead">Welcome <?php echo $username; ?>!</h2>
<a href="home/logout">Logout</a>