01.
' VB.NET
02.
Public Function GetRandomPasswordUsingGUID(ByVal length
as
Integer)
as
String
03.
'Get the GUID
04.
Dim guidResult
as
String = System.Guid.NewGuid().ToString()
05.
06.
'Remove the hyphens
07.
guidResult = guidResult.Replace(
"-"
, String.
Empty
)
08.
09.
'Make sure length is valid
10.
If length <= 0 OrElse length > guidResult.Length Then
11.
Throw New ArgumentException(
"Length must be between 1 and "
& guidResult.Length)
12.
End
If
13.
14.
'Return the first length bytes
15.
Return guidResult.Substring(0, length)
16.
End
Function
17.
18.
19.
20.
public
string GetRandomPasswordUsingGUID(int length)
21.
{
22.
23.
string guidResult = System.Guid.NewGuid().ToString();
24.
25.
26.
guidResult = guidResult.Replace(
"-"
, string.
Empty
);
27.
28.
29.
if
(length <= 0 || length > guidResult.Length)
30.
throw
new
ArgumentException(
"Length must be between 1 and "
+ guidResult.Length);
31.
32.
33.
return
guidResult.Substring(0, length);
34.
}