Categories > Coding > C# >
[Rel] Useless Password Generator | Requested by @Astronemi for Random Project Ideas
Posted
using System;
using System.Linq;
class PasswordGenerator
{
private static readonly string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()-_=+";
static void Main()
{
Console.Write("Enter the desired length of the password: ");
int length = int.Parse(Console.ReadLine());
Console.WriteLine("Generated password:\r\n{GeneratePassword(length)}");
}
public static string GeneratePassword(int length) => new string(Enumerable.Repeat(characters, length).Select(s => s[new Random().Next(s.Length)]).ToArray());
}
OK SO @reversed_coffee wants me to use rngcryptoserviceprovider, so heres it, I HAVE REALLY SH*TTY CODE IM SORRY
using System;
using System.Security.Cryptography;
using System.Text;
class PasswordGenerator
{
private static readonly string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()-_=+";
static void Main()
{
Console.Write("Enter the desired length of the password: ");
int length = int.Parse(Console.ReadLine());
Console.WriteLine($"Generated password: {GeneratePassword(length)}");
}
public static string GeneratePassword(int length)
{
using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
{
byte[] data = new byte[length];
rng.GetBytes(data);
StringBuilder passwordBuilder = new StringBuilder(length);
foreach (byte b in data)
{
passwordBuilder.Append(characters[b % characters.Length]);
}
return passwordBuilder.ToString();
}
}
}
IM SO SORRY FOR MY SH*TTY CODE
easy asl
suggested by @Astronemi from https://forum.wearedevs.net/t/33780 for random project ideas to do bc i was bored
Cancel
Post
Replied
แฌเดฒ๐ แ๐แเดฒ๐แ่ฎ แ แจ แฌโ๐น๐นเดฒ๐
Content length must be 10-5000 chars
Cancel
Post
"your code looks like a decompiled roblox script", - Whoman
Replied
what the HELL is that code it ain't "clean" or anything that's literally unreadable lmao
"haha one line == better!!!! because less lines!!!"
Comments
TERIHAX 30 Reputation
Commented
thats how i like to do it, i like ti keep everything extremely minimal
Cancel
Post
"Questionable intellegence, but I like the mystery" - CubeFaces
https://cdn.discordapp.com/attachments/1136067487847415848/1138948596679589898/sig.png
Replied
The code but readable
using System;
using System.Linq;
class PasswordGenerator
{
private static readonly string characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()-_=+";
static void Main()
{
Console.Write("Enter the desired length of the password: ");
int length = int.Parse(Console.ReadLine());
string password = GeneratePassword(length);
Console.WriteLine("Generated password:\r\n" + password);
}
public static string GeneratePassword(int length)
{
Random random = new Random();
char[] passwordChars = new char[length];
for (int i = 0; i < length; i++)
{
int index = random.Next(characters.Length);
passwordChars[i] = characters[index];
}
return new string(passwordChars);
}
}
Comments
SeizureSalad 36 Reputation
Commented
this is almost worse tbh
TERIHAX 30 Reputation
Commented
@SeizureSalad lmfao
Cancel
Post
nltr | Xaml & C# Developer | Former Fluxus Administrator
------------------------------------------------------------------------------------
๐ Developer of Kronos ๐
Senior Dev of Orbit
Replied
boy what the hell
Cancel
Post
Did I mention I use arch btw?
Replied
i dont get it with ppl making password gens like theres no use unless ur intereted and actively developing for example a softwore that encytps your passwords or saves those random gen passwords or smth like kaspersky
Comments
TERIHAX 30 Reputation
Commented
only reason i did it was because i got bored and asked for things to make and i got suggested to make a pass gen
Cancel
Post
https://media.discordapp.net/attachments/1010636204225601659/1012865624797610044/sKQybOLT.gif
Replied
hiiiiiiiiiiiiiiiii
Cancel
Post
<Hello
Users viewing this thread:
( Members: 0, Guests: 1, Total: 1 )
Comments
TERIHAX 30 Reputation
Commented
"hen brgerb igahopper"?
0