1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
   |  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.Data.SqlClient;
 
 
namespace back_office_SQLI.Models
{
    public class LoginModel
    {
        [Required]
        [Display(Name = "UserName")]
        public string UserName { get; set; }
 
        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }
 
        [Display(Name = "Remember me?")]
        public bool RememberMe { get; set; }
        public bool IsValid(string _username, string _pwd)
        {
 
 
 
 
                string requette = "SELECT count(*) FROM Authentification WHERE Identifiant=@id AND Motdepasse=@pwd";
                SqlConnection cn = new SqlConnection("myConnection");
                SqlCommand commande = new SqlCommand(requette, cn);
                commande.Parameters.AddWithValue("@id", _username);
                commande.Parameters.AddWithValue("@pwd", _pwd);
                cn.Open();
                int result = (int)commande.ExecuteScalar();
                if (result == 1)
                {
                    return true;
                }
                else
                {
                    return false;
                }
 
 
        }
    }
} | 
Partager