L
LavaCreeperKing
Guest
So I am completely new to C#. I have experience in Python and am now trying to learn C#. So after watching some youtube videos to lean a little about the language I thought I would try to replicate a simple program I wrote in Python. All it does is choose random characters ant combines them into a string to create random passwords. The problem that I am having is I can't get the characters to join into one string so I can display it in the console window. When I try to have the console write the password nothing displays.
This is my code:
MyLib:
namespace MyLib
{
public class Rand
{
private static Random Generator = new Random();
public static Char RandChar(string items) //Choose a
random char from string
{
int myIndex = Generator.Next(items.Length);
char l = items[myIndex];
return l;
} //I remove the rest of code here because it is not needed
}
}
Password genererator:
using MyLib;
namespace learning
{
public static class Password
{
private static string Letters = "abcdefghijklmnopqrstuvwxyz";
private static string Numbers = "1234567890";
private static string Symbols = "!@#$%^&*()";
public static string Generate()
{
string word = "";
string[] letters = new string[10];
string[] choice = { "letter", "number", "symbol" };
string[] UL = { "uper", "lower" };
string get;
char c;
for (int i = 0; i <= 9; i++)
{
get = Rand.RandString(choice);
if (get == "letter")
{
c = Rand.RandChar(Letters);
get = Rand.RandString(UL);
if (get == "uper")
{
c = char.ToUpper(c);
letters.Append(c.ToString());
}
else
{
letters.Append(c.ToString());
}
}
if (get == "number")
{
c = Rand.RandChar(Numbers);
letters.Append(c.ToString());
}
if (get == "symbol")
{
c = Rand.RandChar(Symbols);
letters.Append(c.ToString());
}
}
return String.Join(",",letters);
}
}
}
namespace learning
{
class Program
{
static void Main(string[] args)
{
string _word = Password.Generate();
Console.WriteLine(_word);
}
}
}
All I get is a bunch of commas or blank spaces.
Continue reading...
This is my code:
MyLib:
namespace MyLib
{
public class Rand
{
private static Random Generator = new Random();
public static Char RandChar(string items) //Choose a
random char from string
{
int myIndex = Generator.Next(items.Length);
char l = items[myIndex];
return l;
} //I remove the rest of code here because it is not needed
}
}
Password genererator:
using MyLib;
namespace learning
{
public static class Password
{
private static string Letters = "abcdefghijklmnopqrstuvwxyz";
private static string Numbers = "1234567890";
private static string Symbols = "!@#$%^&*()";
public static string Generate()
{
string word = "";
string[] letters = new string[10];
string[] choice = { "letter", "number", "symbol" };
string[] UL = { "uper", "lower" };
string get;
char c;
for (int i = 0; i <= 9; i++)
{
get = Rand.RandString(choice);
if (get == "letter")
{
c = Rand.RandChar(Letters);
get = Rand.RandString(UL);
if (get == "uper")
{
c = char.ToUpper(c);
letters.Append(c.ToString());
}
else
{
letters.Append(c.ToString());
}
}
if (get == "number")
{
c = Rand.RandChar(Numbers);
letters.Append(c.ToString());
}
if (get == "symbol")
{
c = Rand.RandChar(Symbols);
letters.Append(c.ToString());
}
}
return String.Join(",",letters);
}
}
}
namespace learning
{
class Program
{
static void Main(string[] args)
{
string _word = Password.Generate();
Console.WriteLine(_word);
}
}
}
All I get is a bunch of commas or blank spaces.
Continue reading...