Esempio n. 1
0
        public static bool changePassword(string ravkav, string tempPass, string newPass)
        {
            var u = db.Users.Where(x => x.ravkavNum == ravkav).FirstOrDefault();

            if (u == null)
            {
                return(false);
            }
            int id = u.id;
            VertificationCode tempPassEmail = db.VertificationCodes.Where(p => p.fUserID == id).OrderByDescending(o => o.CreateDate).FirstOrDefault();

            if (tempPassEmail == null || tempPassEmail.CreateDate < DateTime.Now.AddMinutes(-30) || tempPass != tempPassEmail.verificationCode)
            {
                return(false);
            }


            u.pass = newPass;
            try
            {
                db.Users.Attach(u);
                db.Entry(u).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Esempio n. 2
0
        public static bool forgotPassword(string ravkav)
        {
            User u = db.Users.FirstOrDefault(x => x.ravkavNum == ravkav);

            if (u == null)
            {
                return(false);
            }
            int fUserID = u.id;
            var vcid    = db.sp_vretificationCode_Insert(fUserID).FirstOrDefault();

            if (vcid == null)
            {
                return(false);
            }
            int    vc = Convert.ToInt32(vcid);
            string to = u.email;

            if (to != null)
            {
                string            from    = "*****@*****.**";
                string            subject = "שחזור סיסמה";
                VertificationCode ver     = db.VertificationCodes.Where(x => x.id == vc).FirstOrDefault();
                if (ver == null)
                {
                    return(false);
                }
                string tempPass = ver.verificationCode;
                string body     = " הסיסמה הזמנית שלך היא" + tempPass;
                SendMail(subject, body, to, from);
                return(true);
            }
            else
            {
                return(false);
            }
        }