ooaat
(Luke Pullin)
1
I have the below function in a model and I want to add code to check that is unique and if not to generate another salt. What do i need to do?
private function randomSalt($length)
{
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double)microtime()*1000000);
$i = 0;
$salt = '' ;
while ($i <= $length)
{
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$salt .= $tmp;
$i++;
}
return $salt;
}
You want to compare it to the database and see if you already have it?
ooaat
(Luke Pullin)
3
Correct. If string is unique return true otherwise try again until function returns true
Dave
(Deventer)
4
public function isUnique($key) {
$condition = "key = :key";
$params = array();
$params['key'] = $key;
$result = YourModel::model()->find($condition, $params);
if ($result == null) {
return true
}
return false;
}
ooaat
(Luke Pullin)
6
I cant get it too work.
Could you please write a complete example. Thanks in advance
Dave
(Deventer)
7
What does the error message say?
The function above should be in a Model and 'YourModel' should be replaced accordingly.