Vb.net 函数不更改基于参数的结果

Vb.net 函数不更改基于参数的结果,vb.net,visual-studio-2012,Vb.net,Visual Studio 2012,我有以下代码: Imports System.Web.Security Public Class Form1 Dim symbols As Integer = 0 Private Sub cbSymbols_CheckedChanged(sender As Object, e As EventArgs) Handles cbSymbols.CheckedChanged If cbSymbols.CheckState = 1 Then s

我有以下代码:

Imports System.Web.Security

Public Class Form1
    Dim symbols As Integer = 0

    Private Sub cbSymbols_CheckedChanged(sender As Object, e As EventArgs) Handles cbSymbols.CheckedChanged
        If cbSymbols.CheckState = 1 Then
            symbols = 1
        ElseIf cbSymbols.CheckState = 0 Then
            symbols = 0
        End If
    End Sub

    Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
        Dim password As String = Membership.GeneratePassword(ComboBox1.SelectedIndex + 6, symbols)
        Label1.Text = password
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Font = New Font("Arial", 14)
        If ComboBox1.Items.Count > 0 Then
            ComboBox1.SelectedIndex = 0    ' The first item has index 0 '
        End If
    End Sub
End Class
但是,无论是否选中我的复选框(cbSymbols),我的密码在勾选时有1个符号,未勾选时有2个符号。有人能帮我诊断这个问题和/或改进我的代码吗?谢谢。

来自

numberOfNonAlphanumericCharactersType:生成的密码中非字母数字字符(如@、#、!、%、&等)的最小数量

这就解释了为什么你会得到这些结果。 我自己也做过几次测试,我甚至得到了一个只有符号的密码

更新

设置特殊字符的最大值不是现成的

有几个选项可供您自己推出:

  • 成员身份生成的密码开始。GeneratePassword
    , 在密码字符串中搜索特殊符号 (
    !char.isleterordigit(c)
    )并且当您到达您的柜台时 将其替换为随机字母或数字

  • 从头开始,创建自己的密码生成器


  • 您是否已设置断点int
    btn\u Generate\u单击
    查看
    符号的值是否正确?第二个参数仅指定符号的最小数量。你希望它施加一个最大值吗?@RogerRowland我确实是,知道怎么做吗?不知道-我希望你必须编写自己的函数,我不知道还有其他选择。啊,原来是这样,这就是我在深夜编程时得到的。你知道如何设置最大数量的符号吗?更新了我的答案。遗憾的是,在.NETFramework(afaik)中没有现成的东西。而且我完全理解深夜节目的内容
    
    Public Shared Function GeneratePassword ( _
        length As Integer, _
        numberOfNonAlphanumericCharacters As Integer _
    ) As String