/// <summary> /// 取得驗證碼(預設15碼 英文+數字) /// </summary> /// <param name="length">驗證碼長度</param> /// <param name="type"></param> /// <returns>驗證碼</returns> public string GetSendCodeStr(int length = 15, SendCodeType type = SendCodeType.Mix) { int.TryParse(TokenLength, out length); string reuslt = string.Empty; reuslt = this.GetRandomStr(length, type); return(reuslt); }
private string GetRandomStr(int length, SendCodeType type) { string str = ""; int beginChar = 'a'; int endChar = 'z'; switch (type) { case SendCodeType.Number: beginChar = 'z' + 1; endChar = 'z' + 10; break; case SendCodeType.ABC: beginChar = 'a'; endChar = 'z'; break; case SendCodeType.Mix: default: beginChar = 'a'; endChar = 'z' + 10; break; } // 生成隨機類 Random random = new Random(); for (int i = 0; i < length; i++) { //int tmp = (beginChar + random.Next(endChar - beginChar)); int tmp = (beginChar + VulnerabilityHelper.RNG_Random.RNG_Next(endChar - beginChar - 1)); // 大於'z'的是數字 if (tmp > 'z') { tmp = '0' + (tmp - 'z'); } str += (char)tmp; } return(str); }