Auto generated id using Crytography


Begin by crearting the interface 
Put the id Field with its Text box
Put the button where the user will be clicking as shown below
 Double click on the button  and copy the code below and paste them after the brace{} of the button since they are create in method form.
Copy the auto() and paste it in the form 

after runing your project will be able to see
 Note: 
if you need to first insert the library below 
This library will allow you to automate the numbers 

using System.Security.Cryptography;

public static string GetUniqueKey(int maxSize)
        {
            // here you are setting the numbers of new characters to be generated
            char[] chars = new char[10000];
            chars = "0123456789".ToCharArray();// here you are settin the range where the ids will be generated
            byte[] data = new byte[1];
            RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
            crypto.GetNonZeroBytes(data);
            data = new byte[maxSize];
            crypto.GetNonZeroBytes(data);
            StringBuilder result = new StringBuilder(maxSize);
            foreach (byte b in data)
            {
                result.Append(chars[b % (chars.Length)]);
            }
            return result.ToString();
        }
        private void auto()
        {
            // no is the name for the textbox where you want to display
            no.Text = "HP/" + GetUniqueKey(4);
        }
 ==============================================================================
Thank you  for visiting luckycoders. please share the code with others

Related Posts
Previous
« Prev Post

Contact Form

Name

Email *

Message *