public static void SendForgotPasswordMail(User user)
        {
            try
            {
                string key = System.Configuration.ConfigurationManager.AppSettings.Get("ekey");
                string encrypted_username = Crypter.Encrypt(key, user.Username);

                MailTemplate mailTemplate = MailTemplatePL.RetrieveMailTemplateByType("Password Reset");
                string fromAddress = mailTemplate.FromEmailAddress;
                string username = mailTemplate.Username;
                string password = mailTemplate.Password;
                string company = mailTemplate.Company;
                string websiteUrl = mailTemplate.WebsiteUrl + "Password/PasswordReset?rq=" + encrypted_username;
                string footer = mailTemplate.Footer;
                string subject = mailTemplate.Subject;
                string mailBody = mailTemplate.Body;

                string body = "";

                body = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/EmailTemplate/PasswordReset.txt"));
                body = body.Replace("#company", company);
                body = body.Replace("#firstname", user.Othernames);
                body = body.Replace("#url", websiteUrl);
                body = body.Replace("#footer", footer);
                body = body.Replace("#body", mailBody);

                MailMessage mail = new MailMessage();
                mail.To.Add(user.Email);
                mail.From = new MailAddress(fromAddress);
                mail.Subject = subject;
                mail.Body = body;
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new System.Net.NetworkCredential(username, password);// Enter seders User name and password
                smtp.EnableSsl = true;
                smtp.Send(mail);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static User RetrieveUserByUsername(string username)
        {
            try
            {
                var existingUser = new User();
                using (var context = new PropertyDBEntities())
                {
                    existingUser = context.Users
                                    .Where(t => t.Username.Equals(username))
                                    .FirstOrDefault();
                }

                return existingUser;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool ChangePassword(string username, string password)
        {
            try
            {
                User existingUser = new User();
                using (var context = new PropertyDBEntities())
                {
                    existingUser = context.Users
                                    .Where(t => t.Username == username)
                                    .FirstOrDefault();
                }

                if (existingUser != null)
                {
                    existingUser.Password = password;
                    existingUser.FirstTime = false;
                    using (var context = new PropertyDBEntities())
                    {
                        context.Entry(existingUser).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }