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 http://blog.codeeffects.com/Article/Generate-Random-Numbers-And-Strings-C-Sharp. 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]        {
        “0”,”2″,”3″,”4″,”5″,”6″,”8″,”9″,
        “a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”,”j”,”k”,”m”,”n”,”p”,”q”,”r”,”s”,”t”,”u”,”v”,”w”,”x”,”y”,”z”,
        “A”,”B”,”C”,”D”,”E”,”F”,”G”,”H”,”J”,”K”,”L”,”M”,”N”,”P”,”R”,”S”,”T”,”U”,”V”,”W”,”X”,”Y”,”Z”
        };
        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

x

We use cookies to ensure the best possible experience on our website. Detailed information on the use of cookies on this site is provided in our Privacy and Cookie Policy. Further instruction on how to disable our cookies can be found there.