"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Tuesday, August 17, 2010

Get Random Password Using GUID

Hi frienz,
Globally unique identifier (GUID) is a special type of identifier used in software  applications to provide a unique reference number. The value is represented as a 32 character hexadecimal character string, such as {21EC2020-3AEA-1069-A2DD-08002B30309D} and usually stored as a 128 bit integer. The term GUID usually, but not always, refers to Microsoft's implementation of the Universally Unique Identifier (UUID) standard.

Here i'm creating a random password Of fixed lenght using GUID.i created a function with a parameter for lenght and it will return the value.

    public string GetRandomPasswordUsingGUID(int length)
    {
        // Getting randam Password
        //Get the GUID
        string guidResult = System.Guid.NewGuid().ToString();

        //Remove the hyphens
        guidResult = guidResult.Replace("-", string.Empty);

        //Make sure length is valid
        if (length <= 0 || length > guidResult.Length)
        {
            throw new ArgumentException("Length must be between 1 and " + guidResult.Length);
        }

        //Return the first length bytes
        return guidResult.Substring(0, length);
    }


Hope this help You...

Have a nice day... 'N happy Coding :)

No comments: