写一段随机生成密码的SQL代码要求密码必须至少包含 8 个字符,至少要有 数字、小写字母、大写字母、符号中的三种。
时间: 2023-04-09 11:01:47 浏览: 152
transfrom_capital_存储过程_sql_字母转大写_
以下是一段随机生成密码的SQL代码,满足密码必须至少包含8个字符,至少要有数字、小写字母、大写字母、符号中的三种要求:
DECLARE @password NVARCHAR(50)
SET @password = ''
WHILE LEN(@password) < 8 OR
(NOT EXISTS(SELECT * FROM sys.all_objects WHERE type_desc = 'S' AND name = 'fn_isdigit') OR
NOT EXISTS(SELECT * FROM sys.all_objects WHERE type_desc = 'S' AND name = 'fn_islower') OR
NOT EXISTS(SELECT * FROM sys.all_objects WHERE type_desc = 'S' AND name = 'fn_isupper') OR
NOT EXISTS(SELECT * FROM sys.all_objects WHERE type_desc = 'S' AND name = 'fn_issymbol')) OR
(SELECT COUNT(DISTINCT SUBSTRING(@password, number, 1)) FROM master..spt_values WHERE type = 'P' AND number BETWEEN 1 AND LEN(@password)) < 3
BEGIN
SET @password = ''
SELECT @password = @password + CHAR(number)
FROM (SELECT TOP 8 number FROM master..spt_values WHERE type = 'P' ORDER BY NEWID()) AS t
END
SELECT @password
注意:这段代码并不是最安全的密码生成方式,仅供参考。
阅读全文