public bool Authenticate(string userID, Password password) { bool authenticated = false; if (userID != null && password != null) { string sql = "select * from tb_UserAccountInfo where UserID=@userid"; SqlCommand sc = new SqlCommand(sql); sc.Parameters.AddWithValue("@userid", userID); DataTable dtuser = da.GetDataTable(sql, sc); if (dtuser != null && dtuser.Rows != null && dtuser.Rows.Count > 0) { try { DataRowWrapper rowWrapper = new DataRowWrapper(dtuser.Rows[0]); Password pwd = rowWrapper.GetTypedColumnValue("Password", typeof(Password)) as Password; if (pwd != null) { if (password.Content == pwd.Content) { authenticated = true; } else { authenticated = false; } // authenticated = password.Equals(pwd); } if (!authenticated) { Password changedPassword = rowWrapper.GetTypedColumnValue("ChangedPassword", typeof(Password)) as Password; if (changedPassword != null) { authenticated = password.Equals(changedPassword); if (authenticated) { AccountInfoProvider.Instance.ChangePassword(userID, changedPassword); } } } } catch (Exception ex) { } } } return authenticated; }
public UserAccountSummary GetUserAccountSummary(string userID) { UserAccountSummary summary = null; if (userID != null) { string sql = "select * from [tb_AccountInfo] where [UserID]=@userid"; SqlCommand sc = new SqlCommand(sql); sc.Parameters.AddWithValue("@userid", userID); DataTable dtinfo = da.GetDataTable(sql, sc); if (dtinfo != null && dtinfo.Rows != null) { summary = new UserAccountSummary(); summary.UserID = userID; foreach (DataRow row in dtinfo.Rows) { DataRowWrapper rowWrapper = new DataRowWrapper(row); AppAccountInfo appAccountInfo = new AppAccountInfo(); appAccountInfo.ApplicationID = rowWrapper.GetColumnValueAsString("ApplicationID"); appAccountInfo.Locked = rowWrapper.GetColumnValueAsBool("Locked"); appAccountInfo.ExpiryTime = dtinfo.Rows[0]["ExpiryTime"].ToString() != "" ? Convert.ToDateTime(dtinfo.Rows[0]["ExpiryTime"].ToString()) : Convert.ToDateTime("1900-01-01"); appAccountInfo.ExpiryTimeSpecified = (appAccountInfo.ExpiryTime.ToString("yyyy-MM-dd") == "1900-01-01") ? false : true; summary.AddAppAccountInfo(appAccountInfo); } } } return summary; }
//tested public AccountInfo GetAccountInfo(string userID, string applicationID) { AccountInfo foundAccountInfo = null; if (userID != null && applicationID != null) { string sql = "select * from [tb_AccountInfo] where [UserID]=@userid and [ApplicationID]=@appid"; SqlCommand sc = new SqlCommand(sql); sc.Parameters.AddWithValue("@userid", userID); sc.Parameters.AddWithValue("@appid", applicationID); DataTable dtinfo = da.GetDataTable(sql, sc); if (dtinfo != null && dtinfo.Rows != null && dtinfo.Rows.Count > 0) { DataRowWrapper rowWrapper = new DataRowWrapper(dtinfo.Rows[0]); foundAccountInfo = new AccountInfo(); foundAccountInfo.ApplicationID = applicationID; foundAccountInfo.UserID = userID; foundAccountInfo.UserName = rowWrapper.GetColumnValueAsString("UserName"); foundAccountInfo.AccountType = (AccountType)rowWrapper.GetEnumColumnValue("AccountType", typeof(AccountType)); foundAccountInfo.Locked = rowWrapper.GetColumnValueAsBool("Locked"); foundAccountInfo.LockedDate = dtinfo.Rows[0]["LockedDate"].ToString() != "" ? Convert.ToDateTime(dtinfo.Rows[0]["LockedDate"].ToString()) : Convert.ToDateTime("1900-01-01"); foundAccountInfo.LockedDateSpecified = (foundAccountInfo.LockedDate.ToString("yyyy-MM-dd") == "1900-01-01") ? false : true; foundAccountInfo.LockCode = rowWrapper.GetColumnValueAsString("LockCode"); foundAccountInfo.ExpiryTime = dtinfo.Rows[0]["ExpiryTime"].ToString() != "" ? Convert.ToDateTime(dtinfo.Rows[0]["ExpiryTime"].ToString()) : Convert.ToDateTime("1900-01-01"); foundAccountInfo.ExpiryTimeSpecified = (foundAccountInfo.ExpiryTime.ToString("yyyy-MM-dd") == "1900-01-01") ? false : true; foundAccountInfo.PaymentInfo = rowWrapper.GetTypedColumnValue("PaymentInfo", typeof(PaymentInfo)) as PaymentInfo; foundAccountInfo.DeviceInfoList = rowWrapper.GetTypedColumnValue("DeviceInfos", typeof(DeviceInfoList)) as DeviceInfoList; } } return foundAccountInfo; }
//tested public UserAccountInfo GetUserAccountInfo(string userID) { UserAccountInfo foundAccountInfo = null; if (!string.IsNullOrEmpty(userID)) { DataTable dtuser = GetUserAccountInfoDT(userID, null, null, false); if (dtuser != null && dtuser.Rows != null && dtuser.Rows.Count > 0) { foundAccountInfo = new UserAccountInfo(); try { foundAccountInfo.UserID = userID; DataRowWrapper rowWrapper = new DataRowWrapper(dtuser.Rows[0]); foundAccountInfo.UserName = rowWrapper.GetColumnValueAsString("UserName"); foundAccountInfo.Password = rowWrapper.GetTypedColumnValue("Password", typeof(Password)) as Password; foundAccountInfo.ChangedPassword = rowWrapper.GetTypedColumnValue("ChangedPassword", typeof(Password)) as Password; foundAccountInfo.EmailAddress = rowWrapper.GetColumnValueAsString("EmailAddress"); foundAccountInfo.AccountType = (AccountType)rowWrapper.GetEnumColumnValue("AccountType", typeof(AccountType)); foundAccountInfo.VipPaymentInfo = rowWrapper.GetTypedColumnValue("VipPaymentInfo", typeof(PaymentInfo)) as PaymentInfo; foundAccountInfo.Activated = rowWrapper.GetColumnValueAsBool("Activated"); foundAccountInfo.Suspended = rowWrapper.GetColumnValueAsBool("Suspended"); } catch (Exception ex) { } } } return foundAccountInfo; }