Friday, 26 December 2014

Strong Random String Password Generation Using C#.Net

12/26/2014 - By Pranav Singh 0



This article will show you how you can generate a string and a random password with specific length using C#.net. This article example I am showing in windows application.



So for this article first we will create a new windows application and add the below code on button click event.

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;

namespace WindowsFormsApplication1
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = RandomString(8);
        }
        public string RandomString(int noOfCharacter)
        {
            string characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            Random r = new Random();
            string randonpassword = new string(
                Enumerable.Repeat(characters, NoofCharacter)
                          .Select(s => s[r.Next(s.Length)])
                          .ToArray());
            return randonpassword;
        }
    }
}

In above code I have created a function named randomstring and in this I have passed the length of the password or the random string which we are going to generate.

Now on button click event call the method to generate the password. Now we have done run the application to check the output.


 

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top