I have this code in PLSQL but I am unable to convert it to SQL Server.
I want to generate a random password that contains a mixture of upper and lowercase, numbers, and special characters in T-SQL based on how many of each the user wants to generate.
How would I convert this Oracle code to T-SQL?
CREATE FUNCTION [DBO].[GENPASS]
(
@p_numbers INT,
@p_specialchar INT,
@p_lowercase TINYINT,
@p_uppercase INT)
returns varchar(4000)
AS
BEGIN
DECLARE @v_length float = @p_numbers + @p_specialchar + @p_lowercase + @p_uppercase;
DECLARE @DECLARE @v_password varchar(200);
DECLARE @v_iterations float = 0;
DECLARE @DECLARE @v_max_iterations float = 50000;
while 1=1 begin
SET @v_password = dbms_random.string('p',@v_length);
SET @v_iterations = @v_iterations + 1;
exit when (dbo.regexp_count(@v_password,'[a-z]') = @p_lowercase
and dbo.regexp_count(@v_password,'[A-Z]') = @p_uppercase
and dbo.regexp_count(@v_password,'[0-9]') = @p_numbers)
or @v_iterations=@v_max_iterations;
end;
if @v_iterations = @v_max_iterations BEGIN
SET @v_password = '';
RETURN NULL;
end;
return(@v_password);
END;