public ChangePasswordResponse ChangePassword(ChangePassword ul) { ChangePasswordResponse res = new ChangePasswordResponse(); try { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[Convert.ToString(ul.AppId)].ConnectionString); string Password = string.Empty; string PasswordKey = string.Empty; string ChangePassword = string.Empty; string changePasswordKey = string.Empty; ChangePassword = DBsecurity.Encrypt(ul.Password, ref changePasswordKey); con.Open(); string query = "Sp_WebSevice"; SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@QueryType", "ChangePassword"); cmd.Parameters.AddWithValue("@UserId", ul.UserId); cmd.Parameters.AddWithValue("@Password", ChangePassword); cmd.Parameters.AddWithValue("@PasswordKey", changePasswordKey); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable ds = new DataTable(); da.Fill(ds); if (ds != null && ds.Rows.Count > 0) { res.status = "Success"; res.message = "Password changed successfully"; res.userId = ul.UserId; } else { res.status = "failure"; res.message = "Password not changed"; res.userId = ""; } con.Close(); } catch (Exception ex) { res.status = "failure"; res.message = "Invalid data"; } return(res); }
public SendEmailResponse ForgetPassword(SendEmail Data) { SendEmailResponse pf = new SendEmailResponse(); try { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[Convert.ToString(Data.AppId)].ConnectionString); con.Open(); string query = "Sp_WebSevice"; SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@QueryType", "ChkEmail"); cmd.Parameters.AddWithValue("@EmailId", Data.emailId); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); if (ds != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows.Count > 0 && ds.Tables[0] != null && Convert.ToInt32(ds.Tables[0].Rows[0]["value"]) == 1) { if (ds.Tables[1].Rows.Count > 0 && ds.Tables[1] != null) { using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { StringBuilder sb = new StringBuilder(); string WebAppUrl = ConfigurationManager.AppSettings["WebAppUrl" + Data.AppId].ToString(); //string SMTPHost = ConfigurationManager.AppSettings["SMTPHost"].ToString(); //string UserId = ConfigurationManager.AppSettings["UserId"].ToString(); //string MailPassword = ConfigurationManager.AppSettings["MailPassword"].ToString(); //string SMTPPort = ConfigurationManager.AppSettings["SMTPPort"].ToString(); //string SMTPEnableSsl = ConfigurationManager.AppSettings["SMTPEnableSsl"].ToString(); string SMTPHost = ConfigurationManager.AppSettings["Amazon_SMTPHost"].ToString(); string UserId = ConfigurationManager.AppSettings["Amazon_UserId"].ToString(); string MailPassword = ConfigurationManager.AppSettings["Amazon_MailPassword"].ToString(); string SMTPPort = ConfigurationManager.AppSettings["Amazon_SMTPPort"].ToString(); string SMTPEnableSsl = ConfigurationManager.AppSettings["Amazon_SMTPEnableSsl"].ToString(); string FromMailId = ConfigurationManager.AppSettings["Amazon_FromMailId" + Data.AppId].ToString(); sb.Append("Dear " + ds.Tables[1].Rows[0]["UserName"].ToString() + ",<br> <br>"); sb.Append("Please click on the below button to set a new Password . <br> <br>"); string User = DBsecurity.Encrypt(ds.Tables[1].Rows[0]["UserId"].ToString()); sb.Append("<a href='" + WebAppUrl + "ChangePassword.aspx?Id=" + User + "' target='_blank'>"); sb.Append("<input style='background-color: #3965a9;color: #fff;padding: 3px 10px 3px 10px;' type='button' value='Change Password' /></a> </div>"); SmtpClient smtpClient = new SmtpClient(); MailMessage mailmsg = new MailMessage(); MailAddress mailaddress = new MailAddress(FromMailId); mailmsg.To.Add(ds.Tables[1].Rows[0]["EmailId"].ToString()); mailmsg.From = mailaddress; mailmsg.Subject = "Recover Password"; mailmsg.IsBodyHtml = true; mailmsg.Body = sb.ToString(); smtpClient.Host = SMTPHost; smtpClient.Port = Convert.ToInt32(SMTPPort); smtpClient.EnableSsl = Convert.ToBoolean(SMTPEnableSsl); smtpClient.UseDefaultCredentials = true; smtpClient.Credentials = new System.Net.NetworkCredential(UserId, MailPassword); smtpClient.Send(mailmsg); } } } pf.message = "Successfully Send"; pf.status = "Success"; } else if (ds.Tables[0].Rows.Count > 0 && ds.Tables[0] != null && Convert.ToInt32(ds.Tables[0].Rows[0]["value"]) == 2) { if (ds.Tables[1].Rows.Count > 0 && ds.Tables[1] != null) { using (StringWriter sw = new StringWriter()) { using (HtmlTextWriter hw = new HtmlTextWriter(sw)) { string WebAppUrl = ConfigurationManager.AppSettings["WebAppUrl"].ToString(); string SMTPHost = ConfigurationManager.AppSettings["SMTPHost"].ToString(); string UserId = ConfigurationManager.AppSettings["UserId"].ToString(); string MailPassword = ConfigurationManager.AppSettings["MailPassword"].ToString(); string SMTPPort = ConfigurationManager.AppSettings["SMTPPort"].ToString(); string SMTPEnableSsl = ConfigurationManager.AppSettings["SMTPEnableSsl"].ToString(); StringBuilder sb = new StringBuilder(); sb.Append("Dear Sir/Mam ,<br> <br>"); sb.Append(" " + ds.Tables[1].Rows[0]["Name"].ToString() + " has requested to set a new password. Please click on the below button to set a new Password. <br> <br>"); string User = DBsecurity.Encrypt(ds.Tables[1].Rows[0]["UserId"].ToString()); sb.Append("<a href='" + WebAppUrl + "ChangePassword.aspx?Id=" + User + "' target='_blank'>"); sb.Append("<input style='background-color: #3965a9;color: #fff;padding: 3px 10px 3px 10px;' type='button' value='Change Password' /></a> </div>"); SmtpClient smtpClient = new SmtpClient(); MailMessage mailmsg = new MailMessage(); MailAddress mailaddress = new MailAddress(UserId); mailmsg.To.Add(ds.Tables[2].Rows[0]["EmailId"].ToString()); mailmsg.From = mailaddress; mailmsg.Subject = "Recover Password"; mailmsg.IsBodyHtml = true; mailmsg.Body = sb.ToString(); smtpClient.Host = SMTPHost; smtpClient.Port = Convert.ToInt32(SMTPPort); smtpClient.EnableSsl = Convert.ToBoolean(SMTPEnableSsl); smtpClient.UseDefaultCredentials = true; smtpClient.Credentials = new System.Net.NetworkCredential(UserId, MailPassword); smtpClient.Send(mailmsg); } } } pf.message = "Successfully Send"; pf.status = "Success"; } else if (ds.Tables[0].Rows.Count > 0 && ds.Tables[0] != null && Convert.ToInt32(ds.Tables[0].Rows[0]["value"]) == -1) { pf.status = "failure"; pf.message = "Not exist"; } } else { pf.status = "failure"; pf.message = "Not exist"; } } catch (Exception ex) { pf.message = "Invalid data"; pf.status = "failure"; } return(pf); }
public UserLogin ChangePassword(UserLoginRequest ul) { try { if (ul.UserPin.Trim() == "") { res.Message = "User cannot be blank"; res.Status = "Failure"; res.UserLoginResponse = ListView; Ulr.UserId = ""; Ulr.UserPin = ""; ListView.Add(Ulr); return(res); } else { if (ul.Password.Trim() != "") { string pass = string.Empty; string passkey = string.Empty; pass = DBsecurity.Encrypt(ul.Password.Trim(), ref passkey); query = "SP_Login"; dbcommand = new SqlCommand(query, conn); dbcommand.Connection.Open(); dbcommand.CommandType = CommandType.StoredProcedure; dbcommand.Parameters.AddWithValue("@QueryType", "APIUpdatePassword"); dbcommand.Parameters.AddWithValue("@UserPin", ul.UserPin); dbcommand.Parameters.AddWithValue("@Password", pass); dbcommand.Parameters.AddWithValue("@PasswordKey", passkey); SqlDataAdapter da = new SqlDataAdapter(dbcommand); DataTable dt = new DataTable(); da.Fill(dt); conn.Close(); if (dt.Rows.Count > 0) { res.Message = "Password has been changed"; res.Status = "success"; res.UserLoginResponse = ListView; Ulr.UserId = ""; Ulr.UserPin = ""; ListView.Add(Ulr); } } else { res.Message = "Password cannot be blank"; res.Status = "Failure"; res.UserLoginResponse = ListView; Ulr.UserId = ""; Ulr.UserPin = ""; ListView.Add(Ulr); } } } catch (Exception ex) { res.Status = "Failure"; res.Message = ex.Message; } finally { dbcommand.Connection.Close(); } return(res); }
public LoginResponsee Logindata(Login ul) { LoginResponsee res = new LoginResponsee(); try { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[Convert.ToString(ul.AppId)].ConnectionString); string Message = ""; string userId = ""; string Username = ""; con.Open(); string query = "Sp_WebSevice"; SqlCommand cmd = new SqlCommand(query, con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@QueryType", "GetUser"); cmd.Parameters.AddWithValue("@UserName", ul.emailId); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet dt = new DataSet(); da.Fill(dt); // bool isFound = false; int i = 0; if (dt != null) { foreach (DataRow row in dt.Tables[0].Rows) { string pin = dt.Tables[0].Rows[i]["UserName"].ToString(); string Passw = DBsecurity.Decrypt(dt.Tables[0].Rows[i]["Password"].ToString(), dt.Tables[0].Rows[i]["PasswordKey"].ToString()); if (Passw == ul.password.Trim()) { Username = Convert.ToString(dt.Tables[0].Rows[i]["UserName"]); res.userName = Username; userId = Convert.ToString(dt.Tables[0].Rows[i]["UserId"]); res.userId = userId; Message = "Login successfully"; res.message = Message; res.status = "success"; break; } else { res.status = "failure"; Message = "Invalid Credentials"; } i++; } } else { res.status = "failure"; res.message = "Invalid Credentials"; res.userName = ""; res.userId = ""; } con.Close(); } catch (Exception ex) { res.status = "server error"; res.message = "Invalid data"; } return(res); }
public UserLogin Login(UserLoginRequest ul) { if (ul.UserPin.Trim() != "" && Validation.ValidateUserPin(ul.UserPin.Trim()) != true) { res.Message = "UserPin Must be 4 digit"; res.Status = "Failure"; res.UserLoginResponse = ListView; Ulr.UserId = ""; Ulr.UserPin = ""; ListView.Add(Ulr); return(res); } else { //bool Flag = true; try { query = "SP_LoginWebApi"; dbcommand = new SqlCommand(query, conn); dbcommand.Connection.Open(); dbcommand.CommandType = CommandType.StoredProcedure; dbcommand.Parameters.AddWithValue("@QueryType", "UserAccess"); dbcommand.Parameters.AddWithValue("@UserPin", ul.UserPin); SqlDataAdapter da = new SqlDataAdapter(dbcommand); DataSet ds = new DataSet(); da.Fill(ds); if (ul.UserPin.Trim() != "" && ul.Password != "") { //if (Convert.ToString(ds.Tables[0].Rows[0]["UserPin"]) == "0") //{ // res.Message = "User has been disabled, please contact administrator!"; // res.Status = "Failure"; // res.UserLoginResponse = ListView; // Ulr.UserId = ""; // Ulr.UserPin = ""; // ListView.Add(Ulr); // return res; //} //else if (Convert.ToString(ds.Tables[0].Rows[0]["UserPin"]) == "-1") //{ // res.Message = "Invalid User Pin!"; // res.Status = "Failure"; // res.UserLoginResponse = ListView; // Ulr.UserId = ""; // Ulr.UserPin = ""; // ListView.Add(Ulr); // return res; //} //else //{ if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { //bool IsLoginfirsttime = Convert.ToBoolean(ds.Tables[0].Rows[0]["LoginFlag"]); string UserType = Convert.ToString(ds.Tables[0].Rows[0]["UserRoleID"]); if (UserType == "1") { #region For Admin string strDbPassword = DBsecurity.Decrypt(Convert.ToString(ds.Tables[0].Rows[0]["Password"]), Convert.ToString(ds.Tables[0].Rows[0]["PasswordKey"])); if (strDbPassword.Trim() != ul.Password.Trim()) { res.Message = "Wrong Password."; res.Status = "Failure"; res.UserLoginResponse = ListView; Ulr.UserPin = ""; Ulr.UserId = ""; ListView.Add(Ulr); return(res); } // else { res.Message = "Valid User."; res.Status = "success"; res.UserLoginResponse = ListView; Ulr.UserId = Convert.ToString(ds.Tables[0].Rows[0]["UserID"]); Ulr.UserPin = ""; ListView.Add(Ulr); return(res); } #endregion } else { //if (IsLoginfirsttime == true) //{ // #region For First Time User Login // string strDbPassword = DBsecurity.Decrypt(Convert.ToString(ds.Tables[0].Rows[0]["Password"]), Convert.ToString(ds.Tables[0].Rows[0]["PasswordKey"])); // if (strDbPassword.Trim() != ul.Password.Trim()) // { // res.Message = "Wrong Password."; // res.Status = "Failure"; // res.UserLoginResponse = ListView; // Ulr.UserId =""; // Ulr.UserPin = ""; // ListView.Add(Ulr); // return res; // } // else // { // res.Message = "Valid User."; // res.Status = "success"; // res.UserLoginResponse = ListView; // Ulr.UserId = Convert.ToString(ds.Tables[0].Rows[0]["UserID"]); // Ulr.UserPin = ""; // ListView.Add(Ulr); // return res; // } // #endregion //} //else //{ #region For Current user //if (Convert.ToString(ConfigurationManager.AppSettings["DefaultPassword"]) == ul.Password.Trim()) //{ res.Message = "Valid User."; res.Status = "Success"; res.UserSiteInfo = UserMultipleSiteInfo; foreach (DataRow row in ds.Tables[0].Rows) { UserMultipleSiteInfo UserMultipleSite = new UserMultipleSiteInfo(); UserMultipleSite.Site = row["AXSiteId"].ToString(); UserMultipleSite.WareHouse = row["WareHouseAX"].ToString(); UserMultipleSiteInfo.Add(UserMultipleSite); } res.UserLoginResponse = ListView; Ulr.UserId = Convert.ToString(ds.Tables[0].Rows[0]["UserID"]); Ulr.UserPin = ul.UserPin; Ulr.IsMove = Convert.ToByte(ds.Tables[0].Rows[0]["IsMove"]); Ulr.IsReportAsFinished = Convert.ToByte(ds.Tables[0].Rows[0]["IsReportAsFinished"]); Ulr.IsQualityCheck = Convert.ToByte(ds.Tables[0].Rows[0]["IsQualityCheck"]); Ulr.IsAssignedPlannedAndUnplanned = Convert.ToByte(ds.Tables[0].Rows[0]["IsAssignedPlannedAndUnplanned"]); Ulr.IsPickAndCount = Convert.ToByte(ds.Tables[0].Rows[0]["IsPickAndCount"]); Ulr.IsMergeStillage = Convert.ToByte(ds.Tables[0].Rows[0]["IsMergeStillage"]); Ulr.IsReturnStillage = Convert.ToByte(ds.Tables[0].Rows[0]["IsReturnStillage"]); Ulr.IsRecieveReturnStillage = Convert.ToByte(ds.Tables[0].Rows[0]["IsRecieveReturnStillage"]); Ulr.IsLookUp = Convert.ToByte(ds.Tables[0].Rows[0]["IsLookUp"]); Ulr.IsUpdateQty = Convert.ToByte(ds.Tables[0].Rows[0]["IsUpdateQty"]); Ulr.IsProductionJournal = Convert.ToByte(ds.Tables[0].Rows[0]["IsProductionJournal"]); Ulr.IsWorkOrderStartEnd = Convert.ToByte(ds.Tables[0].Rows[0]["IsWorkOrderStartEnd"]); Ulr.UserName = Convert.ToString(ds.Tables[0].Rows[0]["UserName"]); Ulr.EmailId = Convert.ToString(ds.Tables[0].Rows[0]["EmailId"]); ListView.Add(Ulr); return(res); //} //else //{ // res.Message = "Wrong Password."; // res.Status = "Failure"; // res.UserLoginResponse = ListView; // Ulr.UserId = ""; // Ulr.UserPin = ""; // ListView.Add(Ulr); // return res; //} #endregion //} } } else { res.Message = "Invalid User."; res.Status = "Failure"; res.UserLoginResponse = ListView; Ulr.UserId = ""; Ulr.UserPin = ""; ListView.Add(Ulr); return(res); } // } } else { res.Message = "Wrong User Pin or Password."; res.Status = "Failure"; res.UserLoginResponse = ListView; Ulr.UserId = ""; Ulr.UserPin = ""; ListView.Add(Ulr); return(res); } } catch (Exception ex) { res.Status = "Failure"; res.Message = ex.Message; } finally { dbcommand.Connection.Close(); } return(res); } }