Created
April 6, 2016 15:15
-
-
Save uqmessias/159624b24a147ba3f5763bbcd9e0aa9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public string GeraSenhaAleatoria(int tamanhoSenha) | |
{ | |
char[] possiveisCaracteres = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$&".ToArray(); | |
// criar um IEnumerable<bool> com o total de itens definido tamanhoSenha | |
string senha = Enumerable.Repeat(true, tamanhoSenha) | |
// Seleciona, randomicamente, alguns caracteres e retorna um IEnumerable<char> com caracteres aleatórios | |
.Select(c => possiveisCaracteres[rnd.Next(possiveisCaracteres.Length)]) | |
// Junta todos os caracteres em uma única string | |
.Aggregate(String.Empty, (current, next) => current.ToString() + next.ToString()); | |
return senha; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment