public ActionResult RegisterAdmin(AdminUser user) { if (!EncryptDecryptData.Encrypt(user.MasterPassword).Equals(Keys.MasterPassword)) { return(Json(new { Status = "Failure", Message = "Master key is not correct" })); } var isAdminExist = _coreContext.Users.Count(e => e.AccountType.Equals(AccountType.Admin)) > 0; if (isAdminExist) { return(Json(new { Status = "Failure", Message = "Admin already exists" })); } var computerName = System.Net.Dns.GetHostName(); user.Password = EncryptDecryptData.Encrypt(user.Password); user.AccountType = AccountType.Admin; user.IsEligible = 1; user.Key = EncryptDecryptData.Encrypt(DateTime.Now.Date.AddDays(90).ToString("dd-MM-yyyy")); user.K1 = EncryptDecryptData.Encrypt(computerName); _coreContext.Users.Add(user); _coreContext.SaveChanges(); return(Json(new { Status = "Success", Link = "/Account/Login" })); }
public ActionResult Register(User user) { if (Session != null && Session["AccountType"].ToString().Equals(AccountType.Admin)) { if (_coreContext.Users.Count() == 6) { return(Json(new { Message = "Maximun 5 Account are only allowed. Please contact admin" })); } var tempUser = _coreContext.Users.ToList(); var lastUser = tempUser.LastOrDefault(); user.AccountId = 1; user.Password = EncryptDecryptData.Encrypt(user.Password); user.AccountType = AccountType.TaxAccount; // accountId is used for session, also act as schema id if (lastUser != null) { user.AccountId = lastUser.AccountId + 1; } _coreContext.Users.Add(user); _coreContext.SaveChanges(); return(Json(new { Message = "Account registered successfully." })); } return(Json(new { Message = "User is not Admin." })); }
public JsonResult ChangeDate(string date) { var value = EncryptDecryptData.Encrypt(date); var profile = _mahadevHwContext.Profiles.First(); // profile.Key = value; _profile = profile; _mahadevHwContext.SaveChanges(); return(Json("Date Changed", JsonRequestBehavior.AllowGet)); }
public bool Authenticate(string username, string password) { var passwordFromDbDecrypted = EncryptDecryptData.Decrypt(Password); if (UserName == username && password == passwordFromDbDecrypted) { return(true); } return(false); }
public JsonResult ChangeSystem(string system) { var coreContext = new CoreContext(); var value = EncryptDecryptData.Encrypt(system); var users = coreContext.Users; foreach (var user in users) { user.K1 = value; } coreContext.SaveChanges(); return(Json("Date Changed", JsonRequestBehavior.AllowGet)); }
public JsonResult Users() { if (Session != null && Session["AccountType"].ToString().Equals(AccountType.Admin)) { var result = _coreContext.Users.ToList().Where(e => !e.AccountType.Equals(AccountType.Admin)); result.ToList().ForEach((user) => { user.Password = EncryptDecryptData.Decrypt(user.Password); }); return(Json(result, JsonRequestBehavior.AllowGet)); } return(Json("User is not admin", JsonRequestBehavior.AllowGet)); }
public JsonResult Revoke(Permission permission) { var validKey = EncryptDecryptData.Encrypt(permission.Key); if (!validKey.Equals(Keys.MasterPassword)) { return(Json("Invalid key", JsonRequestBehavior.AllowGet)); } var profile = _mahadevHwContext.Profiles.First(); // profile.IsEligible = 0; _profile = profile; _mahadevHwContext.SaveChanges(); return(Json("Revoked", JsonRequestBehavior.AllowGet)); }
public void SendMail(string _email, string _name, string _username, string _verificationCode) { this._encryptDecryptData = new EncryptDecryptData(); string _sName = this._appConfig["Data:Email:G_Name:Name"]; string _sEmail = this._appConfig["Data:Email:G_Sndr:Sender"]; string _password = this._appConfig["Data:Email:G_Pass:Password"]; string _subject = this._appConfig["Data:Email:G_Subj:Subject"]; string _host = this._appConfig["Data:Email:G_Host:Host"]; int _port = int.Parse(this._appConfig["Data:Email:G_Port:Port"]); int _enableSsl = int.Parse(this._appConfig["Data:Email:G_ESsl:SSL"]); string _protocol = this._appConfig["Data:Email:G_Protocol:Protocol"]; string _dns = this._appConfig["Data:Email:G_DNS:DNS"]; string _path = this._appConfig["Data:Email:G_Path:Path"]; string _rName = _name; string _rEmail = _email; MailAddress _senderEmail = new MailAddress(_sEmail, _sName); MailAddress _receiverEmail = new MailAddress(_rEmail, _rName); string _mailPassword = this._encryptDecryptData.DecryptData(_password); string _mailSubject = _subject + " " + _rName; string _url = $"{_protocol}://{_dns}{_path}?username={_username}&code={_verificationCode}"; string _mailBody = this.MailBody(_url, _rName, _username); SmtpClient smtp = new SmtpClient { Host = _host, Port = _port, EnableSsl = _enableSsl == 1 ? true : false, DeliveryMethod = SmtpDeliveryMethod.Network, Credentials = new NetworkCredential(_senderEmail.Address, _mailPassword) }; using (MailMessage mess = new MailMessage(_senderEmail, _receiverEmail) { Subject = _mailSubject, Body = _mailBody, IsBodyHtml = true }) { smtp.Send(mess); } }
public UserAccount(string username, string password) { UserName = username; Password = EncryptDecryptData.Encrypt(password); }
public string DecryptPassword() { return(EncryptDecryptData.Decrypt(Password)); }
public ActionResult Login(User user) { try { var users = _coreContext.Users.ToList(); var currentUser = users.FirstOrDefault(e => e.Name == user.Name); if (currentUser == null) { return(Json(new { Message = "User does not exists, Please register" })); } else if (EncryptDecryptData.Decrypt(currentUser.Password) == user.Password) { Session["AccountType"] = currentUser.AccountType; Session["AccountId"] = currentUser.AccountId; if (currentUser.AccountType.Equals(AccountType.Admin)) { return(Json(new { Status = "Success", Link = "/Account/Register" })); } var adminUser = users.FirstOrDefault(e => e.AccountType.Equals(AccountType.Admin)); adminUser.CheckForAccountValidity(); Session["AdminUser"] = adminUser; using (var accountContext = new MahadevHWContext()) { var profile = accountContext.Profiles.FirstOrDefault(); var billSettings = accountContext.BillingSettings.FirstOrDefault(); if (billSettings == null) { var data = new BillingSetting() { IsDiscountRequired = true, IsGstRate = true, IsHSNRequired = true, IsPerRequired = true, BillColumn = "Price", ProductColumn = "SellPrice" }; accountContext.BillingSettings.Add(data); accountContext.SaveChanges(); } if (profile != null) { Session["Profile"] = profile; } else { // new account is created from admin, inject the profile data from corecontext to GSTBillingContext var profileFromAdminUser = new Profile { Address = currentUser.Address, BusinessName = currentUser.BusinessName, Email = currentUser.Email, GSTIN = currentUser.GSTIN, MobileNumber = currentUser.MobileNumber, Owner = currentUser.Owner, EnableStockCount = currentUser.EnableStockCount, State = currentUser.State, StateCode = currentUser.StateCode }; Session["Profile"] = profileFromAdminUser; accountContext.Profiles.Add(profileFromAdminUser); accountContext.SaveChanges(); } } return(Json(new { Status = "Success", Link = "/Billing/New" })); } else { return(Json(new { Status = "Failure", Message = "Incorrect Password." })); } } catch (System.Exception ex) { return(Json(new { Status = "Failure", Message = "Incorrect Password." })); } }