using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KodtestDPSenior
{
///
/// Encapsulates information in the entire collection of instances of
/// persistance class KodtestDPSenior.User
///
public static class Users
{
///
/// Returns an authenticated User if a valid combination of LoginName and
/// PasswordInPlainLanguage are given. Returns null otherwise.
///
///
///
///
public static User Authenticated(string LoginName, string PasswordInPlainLanguage)
{
if (LoginName == null || PasswordInPlainLanguage == null)
{
return null;
}
if (LoginName.Trim() == "")
{
return null;
}
KodtestDPSeniorEntities db = new KodtestDPSeniorEntities();
// "Where" condition below don't take different shift modes into account
var user = db.Users.Where(u => u.LoginName == LoginName.Trim()).FirstOrDefault();
if (user == null)
{
return null;
}
else
{
if (user.LoginName != LoginName.Trim())
{
// Different shift modes
return null;
}
if (user.LoginPassword == Cryptography.GetHash(PasswordInPlainLanguage.Trim()))
{
return user;
}
else
{
return null;
}
}
}
}
}