Business Intelligence

Creating a random password string in SSIS

We need to set a random string in the password field of an ADX Studio implementation. The password will never be used, but it needs to be there to configure single-sign-on.

To do so, I added a script component to the data flow migrating contacts from the old system to the new system. I set the script component as a transform (as opposed to a source or destination), then added an adxpassword column.

I copied a couple of functions from Vlad at In the Input0_ProcessInputRow function, I called the GetRandomString function, setting the returned value to Row.adxpassword.

Job done!

    public int GetRandomNumber(int maxNumber)
        if (maxNumber < 1)
            throw new System.Exception(“The maxNumber value should be greater than 1”);
        byte[] b = new byte[4];
        new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(b);
        int seed = (b[0] & 0x7f) << 24 | b[1] << 16 | b[2] << 8 | b[3];
        System.Random r = new System.Random(seed);
        return r.Next(1, maxNumber);
    public string GetRandomString(int length)
        string[] array = new string[54]        {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        for (int i = 0; i < length; i++) sb.Append(array[GetRandomNumber(53)]);
        return sb.ToString();
    public override void Input0_ProcessInputRow(Input0Buffer Row)
        Row.adxpassword = GetRandomString(20);

Leave a Reply