Ahmad Kharbat

I am trying to create a security image program.. you know to prevent automatic requests.

I have my own font file *.tff .. but i don't know how to use it inside the program.. i tried to declare a new font object, but i couldn't import the font file into it.

is there any way to import my own font file and use it

the second issue is related random numbers..

i have an array of letter {A-Z , 0-9};

and constant length = 5

how can i create an alphanumeric random text out of this array, based on system time changes

another question has just poped up into my mind Smile

can you give me a good example for using md5 objects

thnks alot




Re: Visual C# General 2 simple questions

nielsvanvliet

Answer to Question 2:
Code Snippet

public static class RandomTxt
{
static Random r = new Random(); // Init using multiple source of noise, including the time at which it is executed.
static public string Next()
{
StringBuilder b = new StringBuilder();
for (int i = 0; i < 5; ++i)
{
int n = r.Next(10 + 26);
if (n < 10)
b.Append(n);
else
b.Append((char)('A' + n - 10));
}
return b.ToString();
}

}


Example of RandomTxt, and Short answer to Question 3:
Code Snippet


{
// Example of RandomTxt:
Console.WriteLine(RandomTxt.Next());
Console.WriteLine(RandomTxt.Next());
}
{
// // Example of MD5:
byte[] data = ASCIIEncoding.Default.GetBytes("Hello World !");
System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(data);
foreach (byte b in result)
Console.Write(b.ToString("x"));
Console.WriteLine();
}







Re: Visual C# General 2 simple questions

Ahmad Kharbat

Thanks nielsvanvliet,

that was really helpful..






Re: Visual C# General 2 simple questions

JDPeckham

if you're using WPF, fonts can be put in..

http://msdn2.microsoft.com/en-us/library/ms753303.aspx