Huy Phonghuyphong.com

Password Generator

Huy Phong
Đọc bài viết
Cỡ chữ

Public Function PasswordGenerator(ByVal lngLength As Long) As String

 
On Error GoTo Err_Proc
 
 Dim iChr As Integer
 Dim c As Long
 Dim strResult As String
 Dim iAsc As String
 
 Randomize Timer

 For c = 1 To lngLength
  
   ' Randomly decide what set of ASCII chars we will use
   iAsc = Int(3 * Rnd + 1)
  
    'Randomly pick a char from the random set
   Select Case iAsc
     Case 1
       iChr = Int((Asc("Z") - Asc("A") + 1) * Rnd + Asc("A"))
     Case 2
       iChr = Int((Asc("z") - Asc("a") + 1) * Rnd + Asc("a"))
     Case 3
       iChr = Int((Asc("9") - Asc("0") + 1) * Rnd + Asc("0"))
     Case Else
       Err.Raise 20000, , "PasswordGenerator has a problem."
   End Select
  
   strResult = strResult & Chr(iChr)
 
 Next c
 
 PasswordGenerator = strResult

End function

Xem thêm trong Kinh nghiệm lập trình

Bình luận

Chưa có bình luận được duyệt.

Gửi bình luận

Email không hiển thị công khai. Bình luận được kiểm duyệt trước khi đăng.

Tối đa 10.000 ký tự. Nội dung gửi mới là văn bản thuần.

Tìm một bài viết