Foros del Web » Programación para mayores de 30 ;) » .NET »

LOGIN en WinForms

Estas en el tema de LOGIN en WinForms en el foro de .NET en Foros del Web. Hola maestros: Hoy la consulta va encaminada al acceso de seguridad de mi proyecto. Necesito un ejemplillo de USUARIO-PASSWORD que accediendo a una BD Access ...
  #1 (permalink)  
Antiguo 24/05/2005, 09:08
Avatar de jebado  
Fecha de Ingreso: septiembre-2004
Ubicación: Madrid
Mensajes: 79
Antigüedad: 20 años, 6 meses
Puntos: 0
LOGIN en WinForms

Hola maestros:
Hoy la consulta va encaminada al acceso de seguridad de mi proyecto.
Necesito un ejemplillo de USUARIO-PASSWORD que accediendo a una BD Access de paso al usuario a la ejecución del programa. Comentar que estoy también empezando con acceso a datos y es mi primera base de datos relacional así como sus instrucciones en Visual Basi.NET. Todavía me cuesta entender aquello de las relaciones, Dataset, DataAdapter, instrucciones SQL… pero me va entrando
  #2 (permalink)  
Antiguo 25/05/2005, 08:17
Avatar de jebado  
Fecha de Ingreso: septiembre-2004
Ubicación: Madrid
Mensajes: 79
Antigüedad: 20 años, 6 meses
Puntos: 0
Bueno, pues tengo esto, a ver qué os parece...
Private Sub btnValidar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidar.Click
Dim strConexion As String = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\BD.mdb;"
conexion = New OleDbConnection(strConexion)
conexion.Open()

Dim strComan As String = "SELECT Usuario, Password FROM Usuarios WHERE Usuario = '" & txtUsu.Text & "'" & " AND Password = '" & txtContra.Text & "'"
Dim coman As New OleDbCommand(strComan, conexion)
Dim resul As OleDbDataReader
Dim inicio As New Form1

resul = coman.ExecuteReader

Try
If txtContra.Text = "" And txtUsu.Text = "" Then
MsgBox("ERROR: DEBE INTRODUCIR ALGUN DATO", MsgBoxStyle.Exclamation)
End If

If resul.Read() = True Then
If txtUsu.Text <> resul(0) And txtContra.Text <> resul(1) Then
MsgBox("ERROR: USUARIO Y/O CONTRASEÑA INCORRECTOS", MsgBoxStyle.Critical)
VaciarControles()
Else
psUsuario = txtUsu.Text
psContra = txtContra.Text
inicio.Show()
Me.Hide()

End If
Else
MsgBox("ERROR: USUARIO Y/O CONTRASEÑA INCORRECTOS", MsgBoxStyle.Critical)
VaciarControles()
End If

Catch ex As Exception
MsgBox("ERROR: USUARIO Y/O CONTRASEÑA INCORRECTOS", MsgBoxStyle.Critical)
End Try
resul.Close()
conexion.Close()
End Sub
  #3 (permalink)  
Antiguo 25/05/2005, 08:33
Avatar de RootK
Moderador
 
Fecha de Ingreso: febrero-2002
Ubicación: México D.F
Mensajes: 8.004
Antigüedad: 23 años, 1 mes
Puntos: 50
Solo como comentario podría colocarlo tambien de ésta forma:


Cita:
If txtContra.Text = "" And txtUsu.Text = "" Then
MsgBox("ERROR: DEBE INTRODUCIR ALGUN DATO", MsgBoxStyle.Exclamation)
VaciarControles()
Exit Sub
End If

Dim strConexion As String = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\BD.mdb;"
conexion = New OleDbConnection(strConexion)
conexion.Open()

Dim strComan As String = "SELECT Usuario, Password FROM Usuarios WHERE Usuario = '" & txtUsu.Text & "'" & " AND Password = '" & txtContra.Text & "'"
Dim coman As New OleDbCommand(strComan, conexion)
Dim resul As OleDbDataReader
Dim inicio As New Form1

resul = coman.ExecuteReader()
Dim blnOK as Boolean = False

If resul.Read() Then
blnOk = True
End If

resul.Close()
conexion.Close()


If Not blnOK
MsgBox("ERROR: USUARIO Y/O CONTRASEÑA INCORRECTOS", MsgBoxStyle.Critical)
VaciarControles()
Else
psUsuario = txtUsu.Text
psContra = txtContra.Text
inicio.Show()
Me.Hide()
End If

End Sub
Salu2
__________________
Nadie roba nada ya que en la vida todo se paga . . .

Exentrit - Soluciones SharePoint & Net
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:31.