I need to generated Random String including numbers,char,alphanumneric etc...
thanks i advance
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Sep 5, 2011, 5:38 AM EDT
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 2, 2011, 10:47 PM EDT
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private string RandomString(int StrLength)
{
string CharsList = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ?><*";
char[] chars = CharsList.ToCharArray();
RNGCryptoServiceProvider cryptoGen = new RNGCryptoServiceProvider();
byte[] ByteData = new byte[StrLength];
cryptoGen.GetBytes(ByteData);
StringBuilder ResultStr = new StringBuilder();
foreach (byte byt in ByteData)
{
ResultStr.Append(chars[byt % chars.Length]);
}
return ResultStr.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = RandomString(8);
}
}
}
Thanks
If this post helps you mark it as answer
VulpesRank #55 · 29.2K reputationPosted Sep 3, 2011, 2:55 AM EDT
The random string may contain any character in the ASCII range from 32 (space) to 126 (tilde) inclusive:
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 4, 2011, 10:45 PM EDT
http://www.obviex.com/Samples/Password.aspx
Mittal Sejpal75 reputationPosted Sep 5, 2011, 3:07 AM EDT
A potentially dangerous Request.Form value was detected from the client (TextBox2="HBf@gWjU#)z}m3"). after 3 or 4 times it give like this error
Bharat Bhushan177 reputationPosted Sep 5, 2011, 4:41 AM EDT
http://howtouseasp.net/alpha-numeric-digits-numbers-for-password-asp-net/
Mahesh ChandRank #1 · 393.3K reputationPosted Sep 5, 2011, 6:27 AM EDT
No need to make text colored and size 50. I am sure Vulpes has answered you. Also, see lot of articles in the right side of this.
Thanks! Keep the forums tidy!