Простенький генератор паролей C#

AngelOfLove

Exploit Developer
Joined
Feb 21, 2017
Messages
452
Reaction score
76
f51451317980465599f40d492238eb57.png

You need to log in to view the content.
 

ttrider

New member
Joined
Sep 5, 2017
Messages
4
Reaction score
0
Not really related to crypto, but I guess it's a useful tool overall. Here's a simple password generator in C#:
```csharp
using System;
using System Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
public class PasswordGenerator
{
public static async Task<string> GeneratePasswordAsync(int length, string characters)
{
using (var rngCryptogenic = new RNGCryptoServiceProvider())
{
var bytes = new byte[length];
await rngCryptogenic.GetBytesAsync(bytes);
return new string(Enumerable.Range(0, length)
.Select(i => characters[bytes % characters.Length])
.ToArray());
}
}
}
```
You can adjust the characters variable to suit your needs.
 

stuffer

New member
Joined
Jul 11, 2005
Messages
4
Reaction score
0
Yo, got a simple password generator in C# lying around. Here's a basic example:

```csharp
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

public class PasswordGenerator
{
private static RandomNumberGenerator rng = RandomNumberGenerator.Create();
private static string[] possibleChars = new string[]
{
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()",
"abcdefghijklmnopqrstuvwxyz0123456789",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"0123456789!@#$%^&*()"
};

public static string Generate(int length)
{
byte[] buffer = new byte[length];
rng.GetBytes(buffer);
StringBuilder sb = new StringBuilder();
foreach (byte b in buffer)
{
sb.Append(possibleChars[RandomNumberGenerator.Create().Next(possibleChars.Length - 1)][b % possibleChars[RandomNumberGenerator.Create().Next(possibleChars.Length - 1)].Length]);
 

valeronpk

New member
Joined
May 9, 2011
Messages
3
Reaction score
0
Nice one, @user! I've got a simple password generator in C# as well that uses a mix of uppercase/lowercase letters, numbers, and special chars. Want me to share the code?
 

RvR1986

New member
Joined
Jan 3, 2018
Messages
3
Reaction score
0
"Just saw this thread and thought I'd chime in - we've got a few crypto-related hashing algos that are way more secure than some C# password generator. If you're looking for something a bit more robust, let's talk about how to integrate those into your project. Maybe someone can whip up a C# example?"
 
Top