Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generate same password in the same second
Message
De
12/11/2008 08:29:31
 
 
À
12/11/2008 06:44:40
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01360833
Message ID:
01361292
Vues:
14
>>>I think a better solution would be to include the username and DateTime() in the seed of Random() - yes not static any more
>>
>>Hmm, I'd think the chances of two people attempting to use the same username on the same day are quite a bit higher than 22,000,000 to 1 ?
>
> Really ? Same UserName + same date + same time . We could even add to the seed the output of a static Random ............

Wasn't wide awake this morning - forgetting the "+ same time" bit.....

>
>Update: - we can even throw in a couple of md5 hashes - just for the fun of it
>
>Update2:
>
>The problem with Michel's code is that the 'target space' is so small (double consonants really counts as a single char, and only 11 possibilites or so)
>
>By expanding the space 36 chars ^ 6 - class Michel4 - I do not get any two equal consecutive passwords - at all
>Add to those uppercase >> (26 * 2 + 10)^6 ...
>
>
>Made a simple class
>
>
>	class test
>	{
>	
>		static void Main(string[] args)
>		{
>			string pw1, pw2;
>
>			int dups = 0;
>
>			dups = 0;
>
>			pw1 = Michel4.GeneratePasswordAlpha(6);
>			for (int i = 10000000 * 10 ; --i != 0; )   // times 10 compared to yesterday
>			{
>				pw2 = Michel4.GeneratePasswordAlpha(6);
>
>				if (pw1 == pw2)
>				{
>					Console.WriteLine("{0} {1} {2}", pw1, pw2, pw1 == pw2);
>					dups++;
>				}
>
>				pw1 = pw2;
>			}
>
>
>			Console.WriteLine("Michel4 dups = {0}", dups);
>
>			Console.ReadLine();
>
>		}
>
>	}
>
>	public class Michel4
>	{
>		const string chars = "abcedfghijklmnopqrstuvwxyz0123456789";
>		static readonly int charsLength = chars.Length;
>		static Random rnd = new Random();
>
>		public static string GeneratePasswordAlpha(int tnLength)
>		{
>			int i;
>			StringBuilder sb = new StringBuilder(tnLength);
>
>			for (i = tnLength; --i >= 0; )
>				sb.Append(chars[rnd.Next(charsLength)]);
>			return sb.ToString();
>
>		}
>	}
>
Boy. Michel can have the busiest web site in the world by the time you've finished (G)
Best,
Viv
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform