VB控制台中的随机密码生成器 [英] Random password generator in VB Console

查看:211
本文介绍了VB控制台中的随机密码生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计



如何创建随机密码生成器?



Hey guys

How can I create a random Password Generator?

Module Module1

    Sub Main()
        Dim passwordlength As String
        Dim s As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789?!" 'All characters which will be used for the random passowrd        

         Dim r As Random
        Dim i As Integer
        Console.WriteLine("-- Passwort-Generator --")
        Console.WriteLine("Choose the Password length")
        passwordlength = Console.ReadLine() 'The length of the Password which will be generated
        For i = 1 To passwordlength
        Next

        Randomize()







如何随机选择我的角色池中的字符(字符串s)



例如(每个人都明白什么我想编程):用户在密码长度问题上回答9。现在程序应该随机选择字符串s中定义的所有字符中的9个字符。



对不起我的英语,我来自瑞士:)




How can I randomly choose the characters out of my "character pool" (The string "s")

For example (that everyone understand what I want to program): The users answers with 9 on the Password length question. Now the program should RANDOMLY pick 9 characters out of all the characters which are defined in the string "s".

Sorry for my English, Im coming from Switzerland :)

推荐答案

您已经声明了一个Random类的变量,因此您的方法很好。您基本上从允许的字符串中随机选择9个字符并将它们存储在一个数组中。如果你完成了,你只需从该数组创建密码字符串:

You already declared a variable of Random class so you are on a good way. You basically randomly pick 9 characters from the string of allowed characters and store them in an array. Wne you are done you just create the password string from that array:
Dim s As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789?!" 
Dim r As New Random
Const passwordLength As Integer = 9
Dim passwordChars() As Char = New Char(passwordLength - 1) {}
Dim charIndex As Integer

For i As Integer = 0 To passwordLength - 1
  charIndex = r.Next(s.Length)
  passwordChars(i) = s(charIndex)
Next

Dim password As New String(passwordChars)


您需要使用Random类来生成随机数。但是,这会给你一个随机整数,然后你可以使用这些数字在那些索引上调用不同的字母表。



您可以阅读我之前的文章,为URL创建随机字符串,而不是在URL中使用它们,您可以将其用作密码。它生成了随机字符串,您也可以在应用程序中使用它。



了解随机URL并在ASP.NET中创建它们[ ^ ]



使用此转换器 [ ^ ]转换C#代码到VB.NET。
You need to make a use of the Random class, to generate Random numbers. But, that would give you a Random integer, you can then use those numbers to call different alphabets at those indices.

You can read my previous article to create Random strings for URLs, instead of using them in URLs you can use it as a password. It generated random strings, and you can use it in your application too.

Understanding the Random URLs and Creating them in ASP.NET[^]

Use this converter[^] to convert the C# code to VB.NET.


这篇关于VB控制台中的随机密码生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆