  | 
              
	              
	                
  
    |   | 
   
  
    
        
        ช่วยหน่อยค่ะ ต้องการให้มัน login สู่หน้าเมนู Public Class FormLogin     Private Sub FormLogin_Load     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                Public Class FormLogin 
    Private Sub FormLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
        Dim conn As New SqlClient.SqlConnection() 
        Dim cmd As New SqlClient.SqlCommand() 
        conn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Documents and Settings\User\My Documents\PROJECT MORYA.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True" 
        conn.Open() 
        cmd.Connection = conn 
        'cmd.CommandText = "Insert Into sales (id NOT NULL,date NOT NULL,pharmacist_id NOT NULL,sumtotal NOT NULL) Values ('004','นางดีจัง รักดี','124 ม,'0892222222')" 
        'cmd.ExecuteNonQuery() 
        cmd.CommandText = "Select Password FROM user Where user = Username" 
        conn.Close() 
    End Sub 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
        MessageBox.Show("คุณต้องการออกจากระบบใช่หรือไม่ ?", "ออกจากระบบ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) 
        Me.Close() 
    End Sub 
 
    Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click 
        If (Username.Text = "") Then 
            MessageBox.Show("กรุณาป้อนชื่อผู้ใช้งานระบบด้วยคะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Warning) 
            Username.Focus() 
            Exit Sub 
        End If 
        If (Password.Text = "") Then 
            MessageBox.Show("กรุณาป้อนรหัสผ่านด้วยคะ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Warning) 
            Password.Focus() 
            Exit Sub 
        End If 
        If (Password.Text = "Password") Then 
            FormMainMenu.Show() 
        Else 
            MessageBox.Show("ข้อมูลไม่ถูกต้องกรุณาป้อนข้อมูลใหม่", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning) 
        End If 
    End Sub 
End Class
 
 
  Tag : - - - -              
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2009-07-02 20:48:57 | 
                      By :
                          narttaya | 
                      View :
                          1695 | 
                      Reply :
                          1 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ต้องเอาค่าที่ได้จากการคีย์ในช่อง Username.text  และ Password.text  
ไปเช็คใน DB ครับ เช่น 
Code (VB.NET) 
 Private Sub cmdLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLogin.Click
        If (txtUserName.Text.Trim() = "") OrElse (txtPassword.Text.Trim() = "") Then
            txtUserName.Focus()
            Exit Sub
        End If
        Dim CurrentLogin As Boolean = False
        CurrentLogin = Login(txtUserName.Text, txtPassword.Text)
        If CurrentLogin = True Then
            DBConnString.UserName = txtUserName.Text.Trim()
            frmMain.Show()
            Me.Hide()
        Else
            MessageBox.Show("UserName หรือ Password ที่คุณป้อน ไม่ถูกต้อง !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            txtUserName.Text = ""
            txtUserName.Focus()
            txtPassword.Text = ""
        End If
    End Sub
    Private Function Login(ByVal _UserName As String, ByVal _Password As String) As Boolean
        sb = New StringBuilder()
        sb.Append("SELECT UserName,Password FROM UserName")
        sb.Append(" WHERE (UserName=@UserName)")
        sb.Append(" AND (Password=@Password)")
        sb.Append(" AND (IsNormal='1')")
        Dim sqlLogin As String
        sqlLogin = sb.ToString()
        Dim CurrentIV As Byte() = New Byte() {51, 52, 53, 54, 55, 56, 57, 58}
        Dim CurrentKey As Byte() = {}
        If _UserName.Length = 8 Then
            CurrentKey = Encoding.ASCII.GetBytes(_UserName)
        ElseIf _UserName.Length > 8 Then
            CurrentKey = Encoding.ASCII.GetBytes(_UserName.Substring(0, 8))
        Else
            Dim i As Integer
            Dim AddString As String = _UserName.Substring(0, 1)
            Dim TotalLoop As Integer = 8 - CInt(_UserName.Length)
            Dim tmpKey As String = _UserName
            For i = 1 To TotalLoop
                tmpKey = tmpKey & AddString
            Next
            CurrentKey = Encoding.ASCII.GetBytes(tmpKey)
        End If
        desCrypt = New DESCryptoServiceProvider
        With desCrypt
            .IV = CurrentIV
            .Key = CurrentKey
        End With
        ms = New MemoryStream
        ms.Position = 0
        cs = New CryptoStream(ms, desCrypt.CreateEncryptor, CryptoStreamMode.Write)
        Dim arrByte As Byte() = Encoding.ASCII.GetBytes(_Password)
        cs.Write(arrByte, 0, arrByte.Length)
        cs.FlushFinalBlock()
        cs.Close()
        PwdWithEncrypt = Convert.ToBase64String(ms.ToArray())
        com = New SqlCommand()
        With com
            .CommandText = sqlLogin
            .CommandType = CommandType.Text
            .Connection = Conn
            .Parameters.Clear()
            .Parameters.Add("@UserName", SqlDbType.NVarChar).Value = _UserName
            .Parameters.Add("@Password", SqlDbType.NVarChar).Value = PwdWithEncrypt
            dr = .ExecuteReader()
            If dr.HasRows Then
                dr.Close()
                Return True
            Else
                dr.Close()
                Return False
            End If
        End With
    End Functionend sub
                        
               
               | 
             
            
              
			                                
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2009-07-21 11:31:24 | 
                        By :
                            lee_latee | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |