How to emulate password generation in PHP with PlpgSQL?

From: Andre Lopes <lopes80andre(at)gmail(dot)com>
To: postgresql Forums <pgsql-general(at)postgresql(dot)org>
Subject: How to emulate password generation in PHP with PlpgSQL?
Date: 2010-06-13 12:45:08
Message-ID: AANLkTilnbXFF3MnQe_BGpDU6rfKhYj2C5W2Vtn8hbL4B@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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,

Responses

Browse pgsql-general by date

  From Date Subject
Next Message AI Rumman 2010-06-13 13:14:37 table partition or index
Previous Message Magnus Hagander 2010-06-13 09:51:45 Re: Re: Error on Windows server could not open relation base/xxx/xxx Permission denied