我在vb中有這個函數,它似乎在生成8個字符的密碼之前似乎正在工作,但現在爲每個註冊到該網站的用戶生成相同的密碼。我不確定我出錯的地方,因爲我沒有弄錯這段代碼(代碼不是由我寫的)?任何幫助,將不勝感激。生成隨機8字符密碼的函數
function generatePassword()
Dim i, newPassword
newPassword = ""
For i = 1 to 3
newPassword = newPassword & Mid("ABCDEFGHJKLMNPQRSTUVWXYZ",randomInRange(1,24),1)
Next
For i = 4 to 7
newPassword = newPassword & Mid("23456789",randomInRange(1,8),1)
Next
'For i = 1 to 8
' newPassword = newPassword & Mid("ABCDEFGHJKLMNPQRSTUVWXYZ23456789",randomInRange(1,32),1)
'Next
generatePassword = newPassword
end function
function randomInRange(lo,hi)
randomInRange =(Int((hi - lo + 1) * rnd + lo))
end function
Dim newPassword = generatePassword()
Dim strSql As String = "INSERT INTO Student(" & _
"StudentNo," & _
"Surname," & _
"FirstName," & _
"MiddleName," & _
"Gender," & _
"Pathway," & _
"[Level]," & _
"QubEmail," & _
"[Password]," & _
"HomeEmail," & _
"MobilePhone," & _
"HomeTown," & _
"PlacementYear," & _
"Status," & _
"DateEdited," & _
"HomePhone) " & _
"VALUES " & _
"(" & _
"'" & StudentNo.Text.Replace("'", "''") & "'," & _
"'" & Surname.Text.Replace("'", "''") & "'," & _
"'" & Forename.Text.Replace("'", "''") & "'," & _
"'" & MiddleName.Text.Replace("'", "''") & "'," & _
"'" & ddlGender.SelectedValue & "'," & _
"'" & ddlPathway.SelectedValue & "'," & _
"'" & ddlLevel.SelectedValue & "'," & _
"'" & QUBEmail.Text.Replace("'", "''") & "'," & _
"'" & newPassword & "'," & _
"'" & HomeEmail.Text.Replace("'", "''") & "'," & _
"'" & MobileNo.Text.Replace("'", "''") & "'," & _
"'" & HomeTown.Text.Replace("'", "''") & "'," & _
"" & PlacementYear & "," & _
"'Seeking Placement'," & _
" GETDATE() ," & _
"'" & HomeNo.Text.Replace("'", "''") & "' " & _
")"
Dim addStudent As OleDbDataReader = Database.DoSQLReturnDataReader(strSql)
addStudent.Close()
完美,這工作。謝謝。 – mcclosa