Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var a  = new AddNumbers();
            var x  = a.Add(1970, 4, 16);
            var en = new EncryptString();
            var c  = en.Encrypt("http://msprogrammer.serviciipeweb.ro/");

            Console.WriteLine(en.Encrypt(c));

            var    thisAssembly = Assembly.GetExecutingAssembly();
            string pathAss      = Path.GetDirectoryName(thisAssembly.Location);
            var    assemblies   = thisAssembly.GetReferencedAssemblies();

            foreach (var assembly in assemblies)
            {
                var ass = Assembly.Load(assembly.FullName);

                if (Path.GetDirectoryName(ass.Location) != pathAss)
                {
                    continue;
                }

                Console.WriteLine("-------------------");
                Console.WriteLine(assembly.Name + ":" + assembly.Version);

                //Console.WriteLine(assembly.Name + assembly.Version);
            }
        }
Ejemplo n.º 2
0
 protected void lnkSignIn_Click(object sender, EventArgs e)
 {
     using (CultureDataContext db = new CultureDataContext())
     {
         var query = (from q in db.Users
                      where q.User_Email.Equals(txtEmail.Text.Trim()) &&
                      q.User_Password.Equals(EncryptString.Encrypt(txtPassword.Text))
                      select q).FirstOrDefault();
         if (query != null)
         {
             if (query.User_StatusID == (int)StatusEnum.Approved)
             {
                 Session["User"] = ClientDetails.SerializeClientDetails(new ClientDetails(query.User_ID, query.User_FullName, query.User_Email, query.User_Mobile1, db.GroupUsers.FirstOrDefault(x => x.GroupUser_UserID.Equals(query.User_ID)).GroupUser_GroupID ?? 0, query.User_CommitteeID ?? 0));
                 var per = db.SP_SelectUserPermission(query.User_ID).ToList();
                 List <UserPermissions> tempList = UserPermissions;
                 tempList.AddRange(
                     per.Select(
                         i =>
                         new UserPermissions(i.ModuleID, i.ModuleName, i.PageName, i.PageURL,
                                             bool.Parse(i.Show), bool.Parse(i.Add), bool.Parse(i.Edit), bool.Parse(i.Delete), bool.Parse(i.Index))));
                 UserPermissions = tempList;
                 Response.Redirect("default.aspx");
             }
         }
         else
         {
             ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alertUser",
                                                 "alert('عفوا، المستخدم غير موجود');", true);
         }
     }
 }
Ejemplo n.º 3
0
        public void EncryptDecrypt(string TestValue, string Key)
        {
            //Use a for loop to simulate gen sequence.
            var encryptString1 = EncryptString.Encrypt(TestValue, Key, 1000);
            var encryptString2 = EncryptString.Encrypt(TestValue, Key, 1000);

            Assert.False(string.IsNullOrEmpty(encryptString1));
            Assert.False(string.IsNullOrEmpty(encryptString2));
            Assert.NotEqual(encryptString1, encryptString2); //encryption is salted, so two encryptions should not be the same;

            output.WriteLine("Encrypt success.");

            //decrypt
            var decryptString1 = EncryptString.Decrypt(encryptString1, Key, 1000);

            Assert.Equal(TestValue, decryptString1);

            output.WriteLine("Decrypt1 success.");

            //decypt with modified key.  this will usually throw, due to incompatible key.  when is does pass, ensure the values are not the same.
            try
            {
                var decryptstring = EncryptString.Decrypt(encryptString1, Key + " ", 1000);

                Assert.NotEqual(decryptstring, TestValue);
            } catch (Exception ex)
            {
            }

            output.WriteLine("Decrypt2 success.");
        }
 public void Encrypt(string key, int iterations)
 {
     if (!string.IsNullOrEmpty(ValueRaw))
     {
         Value    = EncryptString.Encrypt(ValueRaw, key, iterations);
         ValueRaw = null;
     }
 }
Ejemplo n.º 5
0
        public bool Encrypt(string key)
        {
            if (!string.IsNullOrEmpty(SecurityKey))
            {
                SecurityKeyEncrypted = EncryptString.Encrypt(SecurityKey, key);
            }

            if (!string.IsNullOrEmpty(EncryptionKey))
            {
                EncryptionKeyEncrypted = EncryptString.Encrypt(EncryptionKey, key);
            }

            return(true);
        }
        public User AddUser(User user)
        {
            using (ApplicationUnit unit = new ApplicationUnit())
            {
                User loginUser = unit.Users.GetAll()
                                 .FirstOrDefault(usr => usr.Username.ToLower() == user.Username.ToLower());

                if (loginUser == null)
                {
                    string password = EncryptString.Encrypt(user.Password, "THEPROJECT");
                    user.Password     = password;
                    user.CreatedDate  = DateTime.Now;
                    user.ModifiedDate = DateTime.Now;
                    unit.Users.Add(user);
                    unit.SaveChanges();
                    return(user);
                }
                return(null);
            }
        }
Ejemplo n.º 7
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     using (CultureDataContext db = new CultureDataContext())
     {
         User u = db.Users.FirstOrDefault(x => x.User_ID == ClientDetails.DeSerializeClientDetails(Session["User"].ToString()).ID);
         if (u != null)
         {
             if (u.User_Password == EncryptString.Encrypt(txtOldPassword.Text))
             {
                 u.User_Password = EncryptString.Encrypt(txtNewPassword.Text);
                 db.SubmitChanges();
                 ScriptManager.RegisterStartupScript(this, GetType(), "alertUser", "$('body').removeClass('modal-open');alert('تم الحفظ بنجاح');", true);
             }
             else
             {
                 ScriptManager.RegisterStartupScript(this, GetType(), "alertUser", "alert('عفوا، كلمة السر القديمة غير صحيحة');$('#changePasswordModal').modal('show');", true);
             }
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 发送更改验证通知
        /// </summary>
        /// <param name="accountId"></param>
        /// <param name="type"></param>
        public bool SendMailOfRetrieveTradePWD(string loginName)
        {
            try
            {
                MailHelper mailHelper = GetMailHelper();
                if (mailHelper.AdminEmail.Length == 0)
                {
                    lblMsg.Text = "<font color='red'>管理员邮箱未设置,请与管理员联系!</font>";
                    return(false);
                }
                Account             account = AccountHelper.GetAccountByLoginName(loginName);
                MailMessageTemplate mt      = new MailMessageTemplate("UserEmailConfig.xml", "密码找回通知");
                string      subject         = mt.Subject.Replace("${LoginName}", account.LoginName);
                string      message         = mt.Body.Replace("${LoginName}", account.LoginName);
                HttpContext context         = HttpContext.Current;

                string url = context.Request.Url.Scheme + "://" + context.Request.Url.Host + ":" + context.Request.Url.Port + "/retrievepassword.aspx?field=" + account.ID + "&validate=" + EncryptString.Encrypt(account.Password);
                message = message.Replace("${ValidateUrl}", string.Format("{0}", "<a href='" + url + "' target='_blank'>" + url + "</a>"));
                mailHelper.Send(account.Email, mailHelper.AdminEmail, subject, message, "Low");
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 9
0
        public void DecryptBadKey()
        {
            var value = EncryptString.Encrypt("test value", "key", 100);

            Assert.Throws <InvalidEncryptionTextException>(() => EncryptString.Decrypt(value, "badKey", 100));
        }
Ejemplo n.º 10
0
 protected void lnkSubmitEditUser_Click(object sender, EventArgs e)
 {
     Page.Validate("vgRegister");
     if (Page.IsValid)
     {
         using (CultureDataContext db = new CultureDataContext())
         {
             try
             {
                 int?member = ddlMember.SelectedValue != "-1" ? (int?)int.Parse(ddlMember.SelectedValue) : null;
                 if (ViewState["ID"] != null)
                 {
                     if (!db.Users.Any(x => x.User_ID != int.Parse(ViewState["ID"].ToString()) && x.User_MemberID == (member ?? 0)))
                     {
                         User u =
                             db.Users.FirstOrDefault(x => x.User_ID.Equals(int.Parse(ViewState["ID"].ToString())));
                         if (u != null)
                         {
                             u.User_MemberID    = member;
                             u.User_CommitteeID = ddlCommittee.SelectedValue != "-1" ? (int?)int.Parse(ddlCommittee.SelectedValue) : null;
                             u.User_FullName    = txtFullName.Text;
                             u.User_Email       = txtRegUsername.Text;
                             u.User_Mobile1     = txtMobile.Text;
                             if (member != null)
                             {
                                 Member m = db.Members.FirstOrDefault(x => x.Member_ID == member);;
                                 m.Member_Name  = txtFullName.Text;
                                 m.Member_Email = txtRegUsername.Text;
                             }
                             GroupUser gu = u.GroupUsers.FirstOrDefault();
                             if (gu != null && ddlGroup.SelectedValue != "-1")
                             {
                                 gu.GroupUser_GroupID = int.Parse(ddlGroup.SelectedValue);
                             }
                             else if (gu != null && ddlGroup.SelectedValue == "-1")
                             {
                                 db.GroupUsers.DeleteOnSubmit(gu);
                             }
                             else if (gu == null && ddlGroup.SelectedValue != "-1")
                             {
                                 GroupUser t = new GroupUser();
                                 t.GroupUser_UserID  = u.User_ID;
                                 t.GroupUser_GroupID = int.Parse(ddlGroup.SelectedValue);
                                 db.GroupUsers.InsertOnSubmit(t);
                             }
                         }
                     }
                     else
                     {
                         ScriptManager.RegisterStartupScript(this, this.GetType(), "Startup", "<script language='javascript'>$('#groupAddModal').modal('show');alert('تم انشاء مستخدم لهذا العضو من قبل');</script>", false);
                         return;
                     }
                 }
                 else
                 {
                     if (!db.Users.Any(x => x.User_MemberID == (member ?? 0)))
                     {
                         User u = new User();
                         u.User_MemberID    = member;
                         u.User_CommitteeID = ddlCommittee.SelectedValue != "-1" ? (int?)int.Parse(ddlCommittee.SelectedValue) : null;
                         u.User_FullName    = txtFullName.Text.Trim();
                         u.User_Email       = txtRegUsername.Text.Trim();
                         u.User_Mobile1     = txtMobile.Text.Trim();
                         u.User_Password    = EncryptString.Encrypt("123456");
                         u.User_StatusID    = (int)StatusEnum.Approved;
                         db.Users.InsertOnSubmit(u);
                         if (member != null)
                         {
                             Member m = db.Members.FirstOrDefault(x => x.Member_ID == member);;
                             m.Member_Name  = txtFullName.Text;
                             m.Member_Email = txtRegUsername.Text;
                         }
                         if (ddlGroup.SelectedValue != "-1")
                         {
                             var g = db.Groups.FirstOrDefault(x => x.Group_ID.Equals(int.Parse(ddlGroup.SelectedValue)));
                             if (g != null)
                             {
                                 GroupUser t = new GroupUser();
                                 t.GroupUser_GroupID = g.Group_ID;
                                 t.User = u;
                                 db.GroupUsers.InsertOnSubmit(t);
                             }
                         }
                     }
                     else
                     {
                         ScriptManager.RegisterStartupScript(this, this.GetType(), "Startup", "<script language='javascript'>$('#groupAddModal').modal('show');$('body').removeClass('modal-open');alert('تم انشاء مستخدم لهذا العضو من قبل');</script>", false);
                         return;
                     }
                 }
                 db.SubmitChanges();
                 ScriptManager.RegisterStartupScript(this, GetType(), "alertUserm", "$('#groupAddModal').modal('hide');$('.modal-backdrop').remove();$('body').removeClass('modal-open');alert('تم الحفظ بنجاح .');", true);
                 ClearUserControls();
                 BindDDL(true);
                 BindUsers();
             }
             catch (Exception ex)
             {
                 string             sPath    = HttpContext.Current.Request.Url.AbsolutePath;
                 System.IO.FileInfo oInfo    = new System.IO.FileInfo(sPath);
                 string             PageName = oInfo.Name;
                 StackTrace         st       = new StackTrace(ex, true);
                 StackFrame         sf       = new StackFrame(0);
                 Common.InsertException(PageName, ex.Message, ex.StackTrace, int.Parse(sf.GetFileLineNumber().ToString()));
                 ScriptManager.RegisterStartupScript(this, GetType(), "alertUser",
                                                     "alert('حدث خطأ اثناء التنفيذ');", true);
             }
         }
     }
     else
     {
         ScriptManager.RegisterStartupScript(this, this.GetType(), "Startup", "<script language='javascript'>$('#groupAddModal').modal('show');</script>", false);
     }
 }
Ejemplo n.º 11
0
 public string Encrypt(string value, string key)
 {
     return(EncryptString.Encrypt(value, key, 1000));
 }