CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Generate a random string based on length in c#

262 Views
Copy Code Show/Hide Line Numbers
public string GetRandomPasswordUsingGUID(int length)
{
string guidResult = System.Guid.NewGuid().ToString();
guidResult = guidResult.Replace("-", string.Empty);
if (length <= 0 || length > guidResult.Length)
throw new ArgumentException("Length must be between 1 and " + guidResult.Length);
return guidResult.Substring(0, length);
}
by pandiyachendur
  June 30, 2010 @ 11:56pm
Tags:

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate