web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Random generation of alphanumeric password

(0) ShareShare
ReportReport
Posted on by

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.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Rajasekhar@MS Profile Picture
    5,569 on at

    Hi

    Have you tried the below, if not try

    forum.mibuso.com/.../how-to-generate-random-code-with-limited-range

  • Verified answer
    Binesh Profile Picture
    7,885 on at

    Hello, Try this code

    Name            DataType    Subtype    Length
    validChar       Char
    CodeString    Code                             20

    // validChar is a char array with 200 dimension

    // Reaming alphabets you have to initialize like that and then  use. 

    // GetRandom is a custom function it returns a code

    GetRandom() : Code[20]
    validChar[1]:='0';
    validChar[2]:='1';
    validChar[3]:='3';
    validChar[4]:='4';
    validChar[5]:='5';
    validChar[6]:='6';
    validChar[7]:='7';
    validChar[8]:='8';
    validChar[9]:='9';

    validChar[10]:='-';
    validChar[11]:='!';
    validChar[12]:='@';
    validChar[13]:='#';
    validChar[14]:='$';
    validChar[16]:='%';
    validChar[16]:='&';
    validChar[17]:='*';
    validChar[18]:='>';
    validChar[19]:='<';
    validChar[20]:='?';
    CLEAR(CodeString);
    RANDOMIZE();
    WHILE STRLEN(CodeString) < 8 DO BEGIN
    CodeString := CodeString + FORMAT(validChar[RANDOM(20)]);
    END;
    EXIT(CodeString);

  • Verified answer
    Tharanga Chandrasekara Profile Picture
    23,118 on at

    I suggest you to write your own code using "RANDOMIZE" and "RANDOM" function available in NAV. Then you will be able to learn things. Just taking a code from someone else's work will never take you to the place you really want to go.

    If you need any additional help just let us know.

    Link : https://msdn.microsoft.com/en-us/library/dd354946.aspx

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans