Hi,
I need to create users in a database function. I'am dealing with a PHP application, the code that generate the password is this:
[code]
public function salt()
{
return substr(md5(uniqid(rand(), true)), 0, 10);
}
public function hash_password($password, $salt=false)
{
if (empty($password))
{
return FALSE;
}
if (FALSE && $salt)
{
return sha1($password . $salt);
}
else
{
$salt = $this->salt();
return $salt . substr(sha1($salt . $password), 0, -10);
}
}
[/code]
It is possible to emulate this in a PlpgSQL function?
I have a function that generates the SHA1 codes
[code]
CREATE OR REPLACE FUNCTION sha1(bytea) returns text AS $$
SELECT encode(digest($1, 'sha1'), 'hex')
$$ LANGUAGE SQL STRICT IMMUTABLE;
[/code]
But I'am not getting how to generate the SALT. Can someone give me a clue on how to do this.
Best Regards,