Search Postgresql Archives

How to emulate password generation in PHP with PlpgSQL?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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,

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux