using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using Pracctice.DMS.BLL; using Pracctice.DMS.Model; using Pracctice.Shared.Security; using Pracctice.DMS.Common; namespace Pracctice.DMS.Web { public partial class Login : BasePage { protected void Page_Load(object sender, EventArgs e) { Page.SetFocus(this.txtName); if (!Page.IsPostBack) { string version = System.Configuration.ConfigurationManager.AppSettings["Version"]; if (version != null) { this.lblVersion.Text = version; } } } protected void btnLogin_Click(object sender, EventArgs e) { // cand folosesti controale de validate TREBUIE sa verifici proprietatea Page.IsValid (validare server) if (Page.IsValid) { string userName = this.txtName.Text.Trim(); string password = this.txtPassword.Text.Trim(); Pracctice.DMS.BLL.User user = new Pracctice.DMS.BLL.User(); new Pracctice.DMS.Web.SettingsCacheProxy().Invalidate(); UserInfo userInfo = new Pracctice.DMS.Web.UserCacheProxy().GetUserByUserName(userName); // check user exists if (userInfo != null) { // check user is active if (userInfo.Activ) { // validate user password string passwordHash = Password.CreatePasswordHash(password, userInfo.PasswordSalt); // use string.Compare is faster if (string.Compare(userInfo.PasswordHash, passwordHash) == 0) { // write audit entry base.AuditWrite(userInfo.UserId, AuditAction.Login); // create authentication ticket and redirect FormsAuthentication.RedirectFromLoginPage(this.txtName.Text.Trim(), false); } else { // invalid password DisplayMessage(Resources.Resource.LoginErrorAuthenticationFailed_LoginPage); } } else { // account inactive DisplayMessage(Resources.Resource.LoginErrorInactiveAccount_LoginPage); } } else { // username doesn't exist DisplayMessage(Resources.Resource.LoginErrorAuthenticationFailed_LoginPage); } } } } }