Hello,
I have to generate the random alphanumeric password.
In NAV through code is it possible to generate randomly?
In C# i have and idea but in NAV i am not sure.
txt1:='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
txt2:='abcdefghijklmnopqrstuvwxyz';
txt3:='123456789';
txt4:='!@#%&';
txtalpha:=txt1+txt2+txt3+txt4;
please suggest me that how to generate the random password by using these variables.
and below is the code according to which i have to develop in NAV.
using System; using System.Security.Cryptography; public static string GetRandomAlphanumericString(int length)
{ const string alphanumericCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789";
return GetRandomString(length, alphanumericCharacters); }
public static string GetRandomString(int length, IEnumerable<char> characterSet)
{ if (length < 0) throw new ArgumentException("length must not be negative", "length");
if (length > int.MaxValue / 8) // 250 million chars ought to be enough for anybody throw new ArgumentException("length is too big", "length");
if (characterSet == null) throw new ArgumentNullException("characterSet"); var characterArray = characterSet.Distinct().ToArray();
if (characterArray.Length == 0) throw new ArgumentException("characterSet must not be empty", "characterSet");
var bytes = new byte[length * 8];
new RNGCryptoServiceProvider().GetBytes(bytes);
var result = new char[length]; for (int i = 0; i < length; i++)
{ ulong value = BitConverter.ToUInt64(bytes, i * 8);
result[i] = characterArray[value % (uint)characterArray.Length]; }
return new string(result); }
PLEASE SUGGEST ME THE CODE.