【发布时间】:2015-06-22 17:47:32
【问题描述】:
我是数据库中 CodeIgniter 的新手,密码字段是使用加密密钥编码的,但是当我想登录时,它与密码不匹配。控制器、视图和模型的名称分别是 Hello、login 和 user_model。
这是我的观点:
<html>
<head>
<title></title>
<style>
.text-danger {
color: red;
}
</style>
<script>
function myFun() {
var r4 = document.getElementById('email').value;
var r5 = document.getElementById('password').value;
if (r4 == "") {
document.getElementById('f4').style.display = "block";
return false;
}
else if (r5 == "") {
document.getElementById('f5').style.display = "block";
return false;
}
}
function myFun4(r) {
if (r != 0) {
document.getElementById('f4').style.display = "none";
}
}
function myFun5(r) {
if (r != 0) {
document.getElementById('f5').style.display = "none";
}
}
</script>
</head>
<body style="background-color: #99BC99">
<br>
<form method="post" action="logindata">
<table border='1' align='center'>
<tr>
<th>Email</th>
<td>
<input type="text" name="email" id="email" onkeyup="myFun4(this.value)">
<span class="text-danger"><?php echo form_error('email'); ?></span>
<span id="f4" class="text-danger" style="display: none">This Field is required</span>
</td>
</tr>
<tr>
<th>Password</th>
<td>
<input type="password" name="password" id="password" onkeyup="myFun4(this.value)">
<span class="text-danger"><?php echo form_error('password'); ?></span>
<span id="f5" class="text-danger" style="display: none">This Field is required</span>
</td>
</tr>
<tr>
<th colspan="2"><button id="submit" name="submit" onclick="return myFun()">Submit</button></th>
</tr>
</table>
</form>
</body>
</html>
我的控制器是
<?php
class Hello extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('session');
$this->load->helper('form');
$this->load->helper('url');
$this->load->helper('html');
$this->load->library('image_lib');
$this->load->database();
$this->load->library('form_validation');
$this->load->model('user_model');
$this->load->library('encrypt');
}
function index() {
$this->load->view('login.php');
}
function logindata() {
$f1 = $this->input->post("email");
$f2 = $this->input->post("password");
$encrypt_pwd2 = $this->encrypt->encode($f2);
$this->form_validation->set_rules("email", "Email", "trim|required");
$this->form_validation->set_rules("password", "Password", "trim|required");
if ($this->form_validation->run() == FALSE) {
$this->load->view('login');
} else {
$data = $this->user_model->get_password($f1, $f2);
$plainpassword = $this->encrypt->decode($data);
if ($plainpassword == $f2) {
$this->dataa['posts'] = $this->user_model->userdata($f1, $f2);
$this->load->view('home', $this->dataa);
} else {
$this->load->view('home');
}
}
}
} ?>
这是我的模型
<?php
class User_model extends CI_Model {
public function __construct() {
parent::__construct();
$this->load->database();
$this->load->library('encrypt');
}
function get_password($f1, $f2) {
$this->db->select('password');
$this->db->from('user_detail');
$this->db->where('email', $f1);
return $this->db->get()->result()->row('password');
}
function userdata($f1, $f2) {
$q = $this->db->get_where('user_detail', array('email' => $f1));
if ($q->num_rows() > 0) {
foreach ($q->result() as $row) {
$dataa[] = $row;
}
return is_array($dataa) ? $dataa : array();
}
}
}
?>
【问题讨论】:
标签: php jquery html mysql codeigniter