情况:我有一个元素数量可变的多维数组。例如
array(N) {
0 => array(3) { ... },
1 => array(8) { ... },
2 => array(1) { ... },
...
M => array(12) { ... },
...
N-1 => array(7) { ... }
}
Run Code Online (Sandbox Code Playgroud)
我想找到这个子数组中元素的最大数量(在上面的例子中,它是 12)。一个简单的解决方案是 O(N) 线性搜索。
<?php
function max_length($2d_array) {
$max = 0;
foreach($2d_array as $child) {
if(count($child) > $max) {
$max = count($child);
}
}
return $max;
}
Run Code Online (Sandbox Code Playgroud)
但是,我不禁想知道是否有一些聪明的技巧可以优化此查找。所以我的问题是一个两部分(尽管对任一部分的答案都可以解决它):
我目前在我的控制器中有这个代码,这里显示一组记录是我的代码
public function view()
{
$title = "View Guardian Information";
$vPa = DB::table('dbo_guardianinformation')
->join('dbo_cities', 'dbo_guardianinformation.CityID', '=' , 'dbo_cities.CityID')
->select('dbo_guardianinformation.ParentAccountID','dbo_guardianinformation.FirstName','dbo_guardianinformation.LastName','dbo_guardianinformation.Roles',
'dbo_guardianinformation.Address','dbo_cities.CityName','dbo_guardianinformation.Status','dbo_guardianinformation.EmailAddress')
->get();
//encrypt decrypt algo
// $sptkey = md5('sample_encryptkey');
// $enPass = rtrim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $sptkey, $defPass, MCRYPT_MODE_ECB)));
// $decPass = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $sptkey, base64_decode($enPass), MCRYPT_MODE_ECB));
return View::make('ssims.view_parentAccount',compact('title','vPa'));
}
Run Code Online (Sandbox Code Playgroud)
我的问题是该列dbo_guardianinformation.Address包含加密记录我目前不知道我应该在哪里放置解密代码,以便当$vPa将传递给视图时它已经包含解密的记录.有任何想法吗?感谢任何愿意提供帮助的人
我需要生成带有以下条件的随机密码:
我尝试过的代码:
function generateRandomPassword() {
//Initialize the random password
$password = '';
//Initialize a random desired length
$desired_length = rand(8, 12);
for($length = 0; $length < $desired_length; $length++) {
//Append a random ASCII character (including symbols)
$password .= chr(rand(32, 126));
}
return $password;
}
Run Code Online (Sandbox Code Playgroud)
如何避免这4个字符=>“ l1o0 ”?
原因:
谢谢!
升级到php7后,BCryptPasswordEncoder会抛出以下错误,例如在使用FOSUserBundle标准注册页面时注册:
"在C:\ xampp\htdocs\ascentary\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder.php第81行"C:不推荐使用'salt'选项来使用password_hash XAMPP\htdocs中\ testproject \供应商\贝哈特\贝哈特的\ src \贝哈特\试验工作\电话\处理器\ RuntimeCallHandler".
我已经跟踪了这个问题,问题是FOS UserManager类,它调用:
/**
* {@inheritDoc}
*/
public function updatePassword(UserInterface $user)
{
if (0 !== strlen($password = $user->getPlainPassword())) {
$encoder = $this->getEncoder($user);
$user->setPassword($encoder->encodePassword($password, $user->getSalt()));
$user->eraseCredentials();
}
}
Run Code Online (Sandbox Code Playgroud)
在这里传递$ user-> getSalt()会抛出错误,因为在php7中,不再允许您将自定义salt传递给bcrypt encoding/password_hash函数.另外,我在基本fos用户实体中看到一个问题,因为在其构造函数中,salt设置为:
$this->salt = base_convert(sha1(uniqid(mt_rand(), true)), 16, 36);
Run Code Online (Sandbox Code Playgroud)
问题:
(1)如何解决我上面发布的错误?也许覆盖了UserManager,或者是否有fos提供的解决方案?
(2)如何正确保护盐,即自动生成?
(3)是否还需要其他更新,例如更新ircmaxell lib?
刚才我在做一个金融项目。在这里,团队正在考虑使用MD5for password hashing。但是,今天很容易复制一个SHA1或MD5密码来解密,包括如果它们是复杂的密码,例如:
My$uper$ecur3PAS$word+448,您可以使用在线页面来解密它,就可以了。中小型开发人员(包括我)使用那些hashing methods,但我认为还不足以提供数据库的安全性。(不包括firewalls,network security,iptables,等等)。
有人可以告诉我解决此漏洞的更好方法是什么吗?
md5 cryptography sha1 password-hash cryptographic-hash-function
所以我正在开发一个使用php,mysql和javascript的网站,还有'sha512'来使用代码加密成员的密码:
$password = filter_input(INPUT_POST, 'p', FILTER_SANITIZE_STRING);
$random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
$password = hash('sha512', $password . $random_salt);
Run Code Online (Sandbox Code Playgroud)
该p值从正在添加:
function formhash(form) {
var password = randomString();
var p = document.createElement("input");
form.appendChild(p);
p.name = "p";
p.type = "hidden";
p.value = hex_sha512(password.value);
password.value = "";
form.submit();
}
function randomString() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 9; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
Run Code Online (Sandbox Code Playgroud)
我的想法是通过输入他们的电子邮件重置用户密码并生成随机的8个字符,然后将其直接发送到他们的电子邮件.我现在面临的问题是如何获取已生成的实际密码(未加密),以便它可以自动发送到请求重置密码的成员的电子邮件中?
我有以下表格供用户填写:
<form name="form" action="" method="POST">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr>
<td width="25%" ><div align="right"><strong>Name:</strong></div></td>
<td width="75%" ><span id="sprytextfield1">
<input id="Cname"name="Name" type="text" placeholder="Please fill in your name">
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td><div align="right"><strong>Email:</strong></div></td>
<td><span id="sprytextfield2">
<input id="Cemail"name="email" type="text" placeholder="e.g sales@company.co.uk">
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
</tr>
<tr>
<td><div align="right"><strong>Phone Number:</strong></div></td>
<td>
<input id="Cphone" name="Phone" type="text"placeholder="e.g. 5555-6666666">
</td>
</tr>
<tr>
<td> </td>
<td><input name="Manufacturer" type="hidden" value="<?php echo $row_emailProduct['Manufacturer']; ?>">
<input name="Model" type="hidden" value="<?php echo $row_emailProduct['Model']; ?>">
<input …Run Code Online (Sandbox Code Playgroud) 需要帮助,因为我还是Yii2的新手.我想在将密码保存到数据库之前加密密码.所以我使用的是sha1,但问题是当我在下面显示的控制器中应用这行代码时,表单中的密码字段有内容.
$ model-> password = sha1($ model-> attributes ['password']);
这是Controller创建方法:
public function actionCreate()
{
$model = new Employeeinformation();
//$model->password = sha1($model->attributes['password']);
$model->created_date = date('Y-m-d H:i:s');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->employee_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
Run Code Online (Sandbox Code Playgroud)
这是形式:
<div class="employeeinformation-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'employee_id')->textInput(['minlength' => true, 'maxlength' => true]) ?>
<?= $form->field($model, 'password')->passwordInput(['maxlength' => true]) ?>
<?= $form->field($model, 'last_name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, …Run Code Online (Sandbox Code Playgroud) 我使用sha1加密来加密我的密码,但我遇到了问题.对于某些用户,登录无效.
我的代码,(注册时)
// all validation is done here
$password = sha1($_POST['password']);
// inserting data is here
Run Code Online (Sandbox Code Playgroud)
在登录我的查询是
$email = $_POST['email'];
$password = sha1($_POST['password']);
select * from users where email = $email and password = $password and status = 1 and deleted = 0;
Run Code Online (Sandbox Code Playgroud)
用户面临密码问题之一,
IM $$人
难道我做错了什么.
请帮我.
我有几个关于PHPpassword_hash函数的问题。
我注意到如果这样做
echo password_hash("12345", PASSWORD_DEFAULT);
Run Code Online (Sandbox Code Playgroud)
然后我得到类似的东西
$2y$10$PgMmle9Ue4o3m7ITJcGa0ucmWXSZgqbJBF9I4qd/aqzn/vQIwbi/O
Run Code Online (Sandbox Code Playgroud)
所以我的问题是
1) 的部分是否会$2y$10$提示所使用的算法,并使攻击者更容易知道原始字符串是什么?
2)我可以将字符串存储在后面$2y$10$并在需要使用密码时将其连接起来吗?
3)为什么$2y$10$使用?未来这种情况会改变吗?那么在我的数据库中,我的密码是$2y$10$,有些是$2y$25$?password_verify使用?一切都会顺利进行
php ×9
cryptography ×3
security ×3
arrays ×1
bcrypt ×1
cryptographic-hash-function ×1
encryption ×1
javascript ×1
laravel ×1
laravel-4 ×1
md5 ×1
passwords ×1
random ×1
sha ×1
sha1 ×1
sha512 ×1
symfony ×1
xss ×1
yii2 ×1