AcCharsGenerator.NewPassword improvements
This commit is contained in:
parent
8e8ec873b2
commit
de2c345b46
|
|
@ -25,7 +25,7 @@ namespace AyCode.Core.Consts
|
|||
public const int MinPlayerNameLength = MinUserNameLength;
|
||||
public const int MaxPlayerNameLength = MaxUserNameLength;
|
||||
|
||||
public const int MinPasswordLength = 6;
|
||||
public const int MinPasswordLength = 8;
|
||||
public const int MaxPasswordLength = 32;
|
||||
public const int MinUserTokenLength = 8;
|
||||
public const int MaxUserTokenLength = 12;
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
namespace AyCode.Core.Helpers
|
||||
{
|
||||
public static class AcCharGenerator
|
||||
public static class AcCharsGenerator
|
||||
{
|
||||
public static readonly char[] Letters;
|
||||
public static readonly char[] Numbers;
|
||||
public static readonly char[] LettersAndNumbers;
|
||||
|
||||
static AcCharGenerator()
|
||||
static AcCharsGenerator()
|
||||
{
|
||||
//"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
|
|
@ -23,6 +23,7 @@ namespace AyCode.Core.Helpers
|
|||
private static char[] GetRandomChars(int minLength, int maxLength) => GetRandomChars(LettersAndNumbers, minLength, maxLength);
|
||||
private static char[] GetRandomChars(char[] sourceChars, int minLength, int maxLength)
|
||||
{
|
||||
if (minLength < 1) throw new ArgumentOutOfRangeException(nameof(minLength), "must have length greater than or equal to 1");
|
||||
var random = new Random();
|
||||
return Enumerable.Repeat(sourceChars, random.Next(minLength, maxLength)).Select(s => s[random.Next(s.Length)]).ToArray();
|
||||
}
|
||||
|
|
@ -32,7 +33,7 @@ namespace AyCode.Core.Helpers
|
|||
return new string(GetRandomChars(AcConst.MinUserTokenLength, AcConst.MaxUserTokenLength));
|
||||
}
|
||||
|
||||
public static string NewPassword()
|
||||
public static string NewPassword(int minLength = AcConst.MinPasswordLength, int maxLength = AcConst.MaxPasswordLength)
|
||||
{
|
||||
return new string(GetRandomChars(AcConst.MinPasswordLength, AcConst.MaxPasswordLength));
|
||||
}
|
||||
Loading…
Reference in New Issue