不改变结果,我有以下代码:功能基于参数
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个符号取消选中。任何人都可以帮助我诊断这个问题和/或改善我的代码吗?谢谢。
有ypou设置断点INT'btn_Generate_Click',看是否symbols'的'值是否正确? – Koen
[根据MSDN](http://msdn.microsoft.com/zh-cn/library/system.web.security.membership.generatepassword.aspx)第二个参数仅指定*最少*符号数。你是否期望它强加一个*最大值*而不是? –
@RogerRowland的确我是,任何想法如何做到这一点? – SCGB