我需要做的事情:
2.强大的访问控制
3.支持大量用户和文件(100多万)
5.加密
建议的解决方案
0)将web应用放在防火墙后面的安全专用服务器上
1) 将文件存储在一个文件中,例如secure\u files/,然后使用mod\u rewrite来限制对此目录的访问。
一些关于:
#Removes access to the secure_files folder by users.
RewriteCond %{REQUEST_URI} ^secure_files.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
然后使用php脚本打开文件,如果用户有权限这样做。所以我可以用:
------
-SQL
------
------
- create files table
-----
CREATE TABLE `files` (
id INT NOT NULL AUTO_INCREMENT,
file_name VARCHAR(50) NOT NULL,
PRIMARY KEY('id')
);
------
- create files table
-----
CREATE TABLE `privileges` (
uesr_id INT NOT NULL,
file_id INT NOT NULL,
);
------
- create users table
-----
CREATE TABLE `users` (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(20) NOT NULL,
email VARCHAR(50) NOT NULL,
password CHAR(40) NOT NULL,
PRIMARY KEY('id')
);
<?php
public function get_user_files($filename)
{
//this is set during login
$user_id = $this->session->userdata('user_id');
//check to see if the user has privileges to access the file and gets the file name
$query = $this->db->join('privileges','privileges.id = files.id')
->select('files.file_name')
->where('privileges.user_id',$user_id)
->where('files.file_name',$file_name)
->limit(1)
->get('files');
$file = $query->row()->files.file_name;
if($file)
{
//user has privileges to access the file so include it
$handle = fopen($file, "rb");
$data['file'] = fread($handle, filesize($file));
fclose($handle);
}
$this->load->view('files',$data);
}
?>
2) 使用CI会话类将用户添加到会话。
控制器检查会话是否已设置:
<?php
public function __construct()
{
parent::__construct();
if($this->secure(array('userType' => 'user')) == FALSE)
{
$this->session->set_flashdata('flashError', 'You must be logged into a valid user account to access this section.');
$this->session->sess_destroy();
redirect('login');
}
}
function secure($options = array())
{
$userType = $this->session->userdata('userType');
if(is_array($options['userType']))
{
foreach($options['userType'] as $optionUserType)
{
if($optionUserType == $userType) return true;
}
}
else
{
if($userType == $options['userType']) return true;
}
return false;
}
?>
3) 在多个web服务器之间循环。我从来没有这样做过,所以我不知道怎么做。我不知道如何处理多个数据库服务器。有什么想法/建议吗?
4) 使用Oracle企业标准数据库审核。我希望我可以使用MySQL,但是我找不到任何审计支持。我可以使用MySQL和PITA。有人用过MySQL的时间点架构(PITA)吗?你能分享你的经历吗?
谢谢你花时间通读这篇文章。
采纳自Redux Auth
关于单向散列。我说加密的错误。我通常会做类似的事情:
salt_length='9';
{
$salt\u length=$此->盐长度;
如果($password===false)
{
返回false;
$salt=$此->盐();
返回$password;
}
专用函数salt()
返回substr(md5(uniqid(rand(),true)),0,$this->盐(长度);
}
?>