Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 answers

573 users

How to generate random password with specific characters in C#

1 Answer

0 votes
using System;
using System.Linq;
  
public class Program
{
    public static string GenerateSpecificRandomPassword(int length, string chars) {
        Random rnd = new Random();
  
        return new string(Enumerable.Repeat(chars, length)
                        .Select(s => s[rnd.Next(s.Length)]).ToArray());  
    }
  
    public static void Main()
    {
        int length = 5;
  
        string password = GenerateSpecificRandomPassword(length, "ABCDEFGhijkl!@#$&");
         
        Console.WriteLine(password);
    }
}
 
 
 
 
  
/*
run:

G@$DG
 
*/

 



answered Aug 17, 2023 by avibootz

Related questions

1 answer 123 views
3 answers 138 views
138 views asked Mar 28, 2023 by avibootz
1 answer 83 views
1 answer 85 views
1 answer 69 views
1 answer 71 views
3 answers 123 views
123 views asked Dec 22, 2024 by avibootz
...