41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using MySqlConnector;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using uWine.Core.Domain.Entities;
|
|
using uWine.Core.Domain.Repositories;
|
|
|
|
namespace uWine.Core.Infrastructure.Repository
|
|
{
|
|
public class MariaDbAuthenticationRepository : MariaDbServerRepository, IAuthenticationRepository
|
|
{
|
|
public MariaDbAuthenticationRepository(IConfiguration configuration) : base(configuration)
|
|
{
|
|
}
|
|
|
|
public bool Valid(User user)
|
|
{
|
|
if (user == null || string.IsNullOrEmpty(user.Username) || string.IsNullOrEmpty(user.Password)) return false;
|
|
using (var conn = Connection())
|
|
{
|
|
var cmd = new MySqlCommand("sp_check_login", conn);
|
|
cmd.CommandType = CommandType.StoredProcedure;
|
|
cmd.Parameters.AddWithValue("@Username", user.Username);
|
|
cmd.Parameters.AddWithValue("@Password", user.Password);
|
|
using (var reader = cmd.ExecuteReader())
|
|
{
|
|
if (reader.Read())
|
|
{
|
|
return reader.GetBoolean("valid");
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|