BandaAncha

  • 🔍 en 📰 artículos ⏎
  • 🔍 en 💬 foros ⏎
  • 🔍 en 👇 este 💬 foro ⏎
  • 🔍 en 👇 este 💬 tema ⏎
Regístrate Regístrate Identifícate Identifícate

crear una contraseña aleatoriamente

oreretaboy

Buenas:

Para poder crear contraseña aleatoriamente podeis utilizar este codigo (Esta comprovado con asp.net). Le teneis que pasar a esta funcion un numero de cuantos caracteres quereis la contraseña.

Public Function GeneratePassword(ByVal passwordLength As Integer) As String
Dim Vowels() As Char = New Char() {"a", "e", "i", "o", "u"}
Dim Consonants() As Char = New Char() {"b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v"}
Dim DoubleConsonants() As Char = New Char() {"c", "d", "f", "g", "l", "m", "n", "p", "r", "s", "t"}
Dim wroteConsonant As Boolean 'boolean
Dim counter As Integer
Dim rnd As New Random()
Dim passwordBuffer As New StringBuilder()

wroteConsonant = False

For counter = 0 To passwordLength
If passwordBuffer.Length > 0 And (wroteConsonant = False) And (rnd.Next(100) passwordBuffer.Append(DoubleConsonants(rnd.Next(DoubleConsonants.Length)), 2)
counter += 1
wroteConsonant = True
Else
If (wroteConsonant = False) And (rnd.Next(100)
passwordBuffer.Append(Consonants(rnd.Next(Consonants.Length)))
wroteConsonant = True
Else
passwordBuffer.Append(Vowels(rnd.Next(Vowels.Length)))
wroteConsonant = False
End If
End If
Next
'size the buffer
passwordBuffer.Length = passwordLength
Return passwordBuffer.ToString
End Function

un saludo

👁 1K7