gpt4 book ai didi

sql - PostgreSQL 密码生成器

转载 作者:搜寻专家 更新时间:2023-10-30 20:52:37 43 4
gpt4 key购买 nike

我需要一些有关 sql pass 生成器的帮助。我已经有一个返回 8 个随机字符的函数,但我必须确定,有小写和大写字符和数字。有什么建议吗?这是我的旧函数。

CREATE FUNCTION f_generate_password() RETURNS text AS $$
DECLARE
password text;
chars text;
BEGIN
password := '';
chars :=
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
FOR i IN 1..8 LOOP
password := password || SUBSTRING(chars,
ceil(random()*LENGTH(chars))::integer, 1);
END LOOP;
return password;
END;
$$
LANGUAGE plpgsql;

最佳答案

这是针对具有相同或相似问题的解决方案:)

CREATE OR REPLACE FUNCTION f_generate_password()
RETURNS text AS
$BODY$
DECLARE
vPassword text;
chars text;
BEGIN
vPassword := '';
chars :=
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
WHILE((select COALESCE(substring(vPassword from '.*[a-z]+.*'),'')) = '' OR (select COALESCE(substring(vPassword from '.*[A-Z]+.*'),'')) = '' OR (select COALESCE(substring(vPassword from '.*[0-9]+.*'),'')) = '') LOOP
vPassword := '';
FOR i IN 1..8 LOOP
vPassword := vPassword || SUBSTRING(chars, ceil(random()*LENGTH(chars))::integer, 1);
END LOOP;
END LOOP;
return vPassword;
END;
$BODY$
LANGUAGE plpgsql;

关于sql - PostgreSQL 密码生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37378450/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com