You are viewing limited content. For full access, please sign in.

Question

Question

Stored Procedures

asked one day ago

Hello,  I have a stored procedure in SQL that i would like to call from a Forms Lookup rule.  The SP generates a random string for a password.  I want the lookup rule to fill the password field in my form with that string.  
 

Here is the Stored Procedure

USE [Laserfiche_XXXX]
GO
/****** Object:  StoredProcedure [dbo].[GeneratePassword]    Script Date: 5/13/2025 2:44:46 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        <Author,,Name>
-- Create date: <Create Date,,>
-- Description:    <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[GeneratePassword]
    -- random string generator
    @characterSet varchar(64) = '0123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ@#$&%' --character set
    , @randomString nvarchar(9) OUTPUT -- the size should be >= the max length required
    , @onechar nvarchar(1) -- one character
    , @i int = 0 -- counter
    , @r int = 0 --random int

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    While @i <= 8 -- put (max length - 1) here it's 10
    begin
        set @r = floor(rand() * LEN(@characterSet))
        set @onechar = SUBSTRING(@characterSet, @r,1)
        set @randomString = concat(@randomString, @onechar); 
        set @i = len(@randomString)
    end
END
 

0 0

Replies

replied 10 hours ago

Have you considered porting that code to javascript? It shouldn't be necessary to get a database involved just to generate a random string.

1 0
replied 9 hours ago

I agree. This seems like an XY Problem.

Here are some resources I found on JavaScript password generation methods with a quick internet search:

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.