Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to generate verification code and take the value in string
Posted
Comments
vinodkumarnie 21-Mar-13 3:15am    
Need more explanations. Give some examples..
Member 9929492 21-Mar-13 3:20am    
i am creating a website. i want to get a verification code in my mobile when i change my password how to generate the code and save database...
vinodkumarnie 21-Mar-13 4:35am    
Which type of code you want..? integers or alphanumeric or alphabets..? Show some examples..
Member 9929492 21-Mar-13 4:42am    
mix of char & int

1 solution

Try below..
C#
using System.Text;
using System.IO;


  static int RandomNumber(int min, int max)
    {
        Random random = new Random();
        return random.Next(min, max);
    }

private string RandomString(int size)// for random alphabets
    {
        StringBuilder builder = new StringBuilder();
        Random random = new Random();
        char ch;
        for (int i = 0; i < size; i++)
        {
            ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
            builder.Append(ch);
        }

        return builder.ToString();
    }
    static class RandomUtil // for random alphanumerics
    {
        /// <summary>
        /// Get random string of 11 characters.
        /// </summary>
        /// <returns>Random string.</returns>
        public static string GetRandomString()
        {
            string path = Path.GetRandomFileName();
            path = path.Replace(".", ""); // Remove period.
            return path;
        }
    }

     // random function where ever you wanted
     Label1.Text = RandomUtil.GetRandomString(); // for alphanumeric
     Label2.Text = RandomString(10); // for alphanumeric of length 10
     Label3.Text = RandomNumber(10,10000); // for random number between 10 and 10000

refer below link..
http://www.dotnetperls.com/random-string[^]
 
Share this answer
 
Comments
Member 9929492 21-Mar-13 5:18am    
thank u...
vinodkumarnie 21-Mar-13 5:21am    
welcome..
vinodkumarnie 21-Mar-13 5:25am    
After successfully change of password you generate code and send it to your mobile.
Member 9929492 21-Mar-13 6:09am    
string path = Path.GetRandomFileName();
and

Label1.Text = RandomUtil.GetRandomString(); // for alphanumeric
Label2.Text = RandomString(10); // for alphanumeric of length 10
Label3.Text = RandomNumber(10,10000); // for random number between 10 and 10000
this code is not working
Member 9929492 21-Mar-13 6:11am    
before send verification code
the verification code is matching then successfully changed the pwd

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900