是否可以使用 return ReserveFormSet(
data=(
self.request.POST
if self.request.method == 'POST'
else None
),
initial=self.tickets,
form_kwargs={
'organizer': self.request.organizer,
'event': self.request.event,
'user_order_reference': self.request.session.get('order_reference'),
},
discount_code_session=self.discount_code,
)
函数从我的用户表中更改所有现有密码来运行查询?
我正在使用CI,但根本无法正常工作!
我的模特
password_hash()
*请注意,我正在加载自定义public function EncryptDB($filters = NULL){
$ci =& get_instance();
$ci->load->helper('hash');
$query = "UPDATE users SET password = {hash_password(password)}";
$sql = $this->db->query($query);
}
以对其进行哈希处理。
我的助手
helper
我的控制器
function hash_password($password){
$configs = array(
"cost" => 10 # custo de processamento (10 -> default)
);
$password = password_hash($password, PASSWORD_DEFAULT, $configs);
return $password;
}
答案 0 :(得分:1)
尝试此解决方案。
users
表具有名为id
的主键。对于固定表,此代码可能应该只运行一次。
function updatePasswords(){
$this->db->trans_start();
$offset = 0;
do{
$selectQuery = $this->db
->limit(100, $offset)
->get('users');
$results = $selectQuery->result();
foreach ($results as $user){
$configs = array(
"cost" => 10 # custo de processamento (10 -> default)
);
$hashedPassword = password_hash($user->password, PASSWORD_DEFAULT, $configs);
$this->db
->set('password', $hashedPassword)
->where('id', $user->id)
->update('users');
}
$offset += $selectQuery->num_rows();
} while ($selectQuery->num_rows() > 0);
$this->db->trans_complete();
if ($this->db->trans_status()){
die("[+] operation successfully completed.");
}
else{
die("[-] operation encounted an error somewhere. not data was updated.");
}
}