public ActionResult updatePwd(UserExt u) { if (u != null) { reflectModel.setValues(u); if (u.nick_name.Length >= 3 && u.pwd.Length >= 6 && u.newpwd.Length >= 6 && !u.pwd.Equals(u.newpwd)) { try { string old_hash_pwd = HashTools.SHA1_Hash(u.pwd); // 旧的hash密码 using (WeiQingEntities db = new WeiQingEntities()) { var user = db.user.Where(p => p.nick_name.Equals(u.nick_name) && p.pwd.Equals(old_hash_pwd)).FirstOrDefault(); if (user != null && u.nick_name.Equals(user.nick_name)) { user.pwd = HashTools.SHA1_Hash(u.newpwd); int res = db.SaveChanges(); // 修改密码 if (res > 0) { Session["user"] = null; } return(Content(res.ToString())); } return(Content("旧密码不正确")); } } catch (Exception ex) { return(Content("后台出现错误")); } } return(Content("修改失败")); } return(Content("参数错误")); }
/// <summary> 使用外部的的<see cref="WzFileStream"/>儲存資料 </summary> public bool Write(WzFileStream zs) { this.Hash = HashTools.GenerateArchiveVersionHash(this.Version.ToString()); // header zs.Write(new byte[] { (byte)'P', (byte)'K', (byte)'G', (byte)'1' }, 4); zs.Write8(0); //Reserve zs.Write4u(0); //Reserve zs.WriteString(this.Description); // data long off = zs.Tell(); this.DataOffset = (uint)off; zs.BaseOffset = this.DataOffset; zs.Write2u((ushort)HashTools.EncryptArchiveVersionHash(this.Hash)); this.RootDirectory.Update(); this.RootDirectory.Write(zs); long endoff = zs.Tell(); // rewrite size, offset zs.Seek(4); zs.Write8(endoff - off); zs.Write4u((uint)off); // end write zs.Flush(); return(true); }
public static void RemoveBackup(bool encrypted, bool cache, Random?random = null) { (Core core, Dictionary <string, byte[]> verifyfilepaths, MetadataNode vfsroot, BPlusTree <byte[]> vfsdatastore)testdata; if (encrypted) { testdata = InitializeNewCoreWithStandardFiles(0, 1, cache: cache, random: random); } else { testdata = InitializeNewCoreWithStandardFiles(1, 0, cache: cache, random: random); } var(core, _, vfsroot, _) = testdata; var bh1 = core.RunBackup("test", "run1"); //System.Threading.Thread.Sleep(40); // Allow async writes to finish vfsroot.AddDirectory("src", VirtualFSInterop.MakeNewDirectoryMetadata("sub")); var bh2 = core.RunBackup("test", "run2"); //System.Threading.Thread.Sleep(40); // Allow async writes to finish // Full hash test core.RemoveBackup("test", HashTools.ByteArrayToHexViaLookup32(bh1.GetOrThrow())); //System.Threading.Thread.Sleep(40); // Allow async writes to finish // Just prefix core.RemoveBackup("test", HashTools.ByteArrayToHexViaLookup32(bh2.GetOrThrow()).Substring(0, 10)); // All backups deleted Assert.AreEqual(core.GetBackups("test").backups.Count(), 0); }
public void TestSHA1() { string words = "zxczxczxczxczxczxczxczxcxzczxczxczx"; string sha1 = HashTools.SHA1Encrypt(words); Debug.Log("sha1 =>" + sha1); }
public ActionResult adminLogin(user u) { if (u != null) { // 查询用户的数据,判断权限 reflectModel.setValues(u); if (u.nick_name.Length > 0 && u.pwd.Length > 0) { u.pwd = HashTools.SHA1_Hash(u.pwd); using (WeiQingEntities db = new WeiQingEntities()) { var user = db.user.Where(x => (x.nick_name.Equals(u.nick_name) || x.email.Equals(u.nick_name)) && x.pwd.Equals(u.pwd) && x.state == 1).FirstOrDefault(); if (user != null && user.is_admin && user.id > 0) { Session["user"] = user; string ip = Tools.GetRealIP(); login_log log = new login_log() { uid = (int)user.id, login_ip = ip, login_time = DateTime.Now }; db.login_log.Add(log); db.SaveChanges(); return(Content("1")); } } } return(Content("-2")); } return(Content("-1")); }
/// <summary> /// 密码默认初始化为666666 /// </summary> /// <param name="name">用户名</param> /// <returns></returns> public ActionResult resetUserPwd(string name = "", int id = 0, string newpwd = "") { var state = System.Configuration.ConfigurationManager.AppSettings["InitPwd"]; if ("1".Equals(state)) { using (WeiQingEntities db = new WeiQingEntities()) { if (id > 0) { var u = db.user.Where(x => x.id == id).FirstOrDefault(); if (u != null && u.id > 0) { if (newpwd != null && newpwd.Length >= 6) { u.pwd = HashTools.SHA1_Hash(newpwd); } else { u.pwd = HashTools.SHA1_Hash("666666"); } int res = db.SaveChanges(); if (res > 0 && string.IsNullOrEmpty(newpwd)) { return(Content("<script>alert('初始化密码成功,密码为666666,请立即修改密码')</script>")); } else if (res > 0) { return(Content("<script>alert('初始化密码成功,密码为" + newpwd + " ,请立即修改密码')</script>")); } } } if (name != null && name.Length > 0) { var u = db.user.Where(x => x.nick_name.Equals(name)).FirstOrDefault(); if (u != null && u.id > 0) { if (newpwd != null && newpwd.Length >= 6) { u.pwd = HashTools.SHA1_Hash(newpwd); } else { u.pwd = HashTools.SHA1_Hash("666666"); } int res = db.SaveChanges(); if (res > 0 && string.IsNullOrEmpty(newpwd)) { return(Content("<script>alert('初始化密码成功,密码为666666,请立即修改密码')</script>")); } else if (res > 0) { return(Content("<script>alert('初始化密码成功,密码为" + newpwd + " ,请立即修改密码')</script>")); } } } } } return(Content("设置失败,请检查是否在应用程序设置中开启了此接口,或者已设置为初始密码")); }
internal override void Update() { if (this.Stream != null) { this.Checksum = (int)HashTools.GenerateChecksum(this.Stream, this.Offset, this.Size); } }
public void HashToolsSHA() { // Use the Assert class to test conditions Assert.That(HashTools.StringToSHA("HelloWorld"), Is.EqualTo(HashTools.StringToSHA("HelloWorld"))); // Use the Assert class to test conditions Assert.That(HashTools.StringToSHA("HelloWorld"), Is.Not.EqualTo(HashTools.StringToSHA("ByeByeWorld"))); }
public void Insert(Utilisateur u) { /* if(((SQLRepositoryUtilisateur)repoUserCustomize).findByEmail(u.Email) != null) * { * throw new UserNameIsException("Le UserName existe déjà. Veuillez choisir un autre UserName!!"); * } * * if (((SQLRepositoryUtilisateur)repoUserCustomize).findByUserName(u.UserName) != null) * { * throw new EmailIsException("L'adresse mail existe déjà. Veuillez choisir un autre adresse mail!!"); * }*/ List <Utilisateur> utilisateursDao = FindUtilisateurs(); for (int i = 0; i < utilisateursDao.Count; i++) { if (u.UserName == utilisateursDao[i].UserName) { throw new UserNameIsException("Le UserName existe déjà. Veuillez choisir un autre UserName!!"); } if (u.Email == utilisateursDao[i].Email) { throw new EmailIsException("L'adresse mail existe déjà. Veuillez choisir un autre adresse mail!!"); } } u.Password = HashTools.ComputeSha256Hash(u.Password); repo.Insert(u); }
/// <summary> 使用外部的<see cref="WzFileStream"/>讀取資料 </summary> public bool Read(WzFileStream zs) { string identifier = zs.ReadString(4); if (!identifier.Equals("PKG1")) { return(false); } this.DataSize = zs.Read8(); this.DataOffset = zs.Read4u(); this.Description = zs.ReadString((int)(this.DataOffset - zs.Tell())); zs.BaseOffset = this.DataOffset; ushort cryptedHash = zs.Read2u(); this.RootDirectory.Offset = (uint)zs.Tell(); for (int j = 0; j < 0xFFFF; j++) { this.Hash = HashTools.GenerateArchiveVersionHash(j.ToString()); if (HashTools.EncryptArchiveVersionHash(this.Hash) == cryptedHash) { zs.StringPool.Clear(); if (this.RootDirectory.Read(zs)) { this.Version = j; return(true); } } } return(false); }
public void TestMD5() { string words = "zxczxczxczxczxczxczxczxcxzczxczxczx"; string md5 = HashTools.MD5Encrypt(words); Debug.Log("md5 =>" + md5); }
public byte[] Hash(string text) { var words = text.Split(); var result = new int[_byteCount * 8]; foreach (var grams in words.GetNGrams(_gramCount)) { var gram = string.Join(' ', grams); var hash = new BitArray(HashTools.GetByteHash(gram, _byteCount)); for (var i = 0; i < hash.Length; i++) { if (hash[i]) { result[i]++; } else { result[i]--; } } } var bits = result .Select(x => x > 0) .ToArray(); var bytes = new byte[_byteCount]; new BitArray(bits).CopyTo(bytes, 0); return(bytes); }
/// <summary> /// Gets the hash. /// </summary> /// <returns>The hash.</returns> /// <param name="result">Result.</param> internal static string ToHash(this IDocumentResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } var c = (result.Content?.ToString(Cultures.Invariant) ?? string.Empty) + (result.Date == null ? "(none)" : result.Date.Value.ToEpoch().ToString(Cultures.Invariant)) + (result.Slug ?? "(none)") + (result.Draft) + (result.DocumentIdentifier.ProjectId ?? "(none)") + (result.DocumentIdentifier.DocumentType.ToString() ?? "(none)") + (result.DocumentIdentifier.DocumentTypeId ?? "(none)") + (result.DocumentIdentifier.DocumentId ?? "(none)") + ((result.DocumentIdentifier.Index ?? 0).ToString(Cultures.Invariant)); if (result.OriginalMeta != null) { c += JsonConvert.SerializeObject(result.OriginalMeta); } if (result.Meta != null) { c += JsonConvert.SerializeObject(result.Meta); } return(HashTools.GetHash(c, HashTools.HashType.SHA1)); }
public static string GetLoginHash(string md5pass) { var passContent = $"=={md5pass}.{Config.Config.Options.PassHashKey1}"; var hashedPass = HashTools.HmacSha1Base64(passContent, Config.Config.Options.PassHashKey2); return(hashedPass); }
public void StringToHashRegion() { // Use the Assert class to test conditions Assert.That(HashTools.StringToHash("HelloWorld".ToCharArray(), 1, 4), Is.EqualTo(HashTools.StringToHash("HelloWorld".ToCharArray(), 1, 4))); // Use the Assert class to test conditions Assert.That(HashTools.StringToHash("HelloWorld".ToCharArray(), 1, 4), Is.Not.EqualTo(HashTools.StringToHash("ByeByeWorld".ToCharArray(), 1, 4))); }
public static string GetRandomKey() { var random = new Random(); var randomSeed = random.Next(0, int.MaxValue); var rk = HashTools.Md5Base64(randomSeed.ToString()); return(rk); }
public ActionResult getPwd(user u) { if (u != null) { reflectModel.setValues(u); if (u.nick_name.Length >= 3 && Tools.IsEmail(u.email)) { try { using (WeiQingEntities db = new WeiQingEntities()) { var user = db.user.Where(p => p.nick_name.Equals(u.nick_name) && p.email.Equals(u.email)).FirstOrDefault(); // 检查用户名和邮箱是否匹配 if (user != null && u.nick_name.Equals(user.nick_name)) { DateTime dt = DateTime.Now; string ip = Tools.GetRealIP(); // 获取客户端ip // 检查当前 uid 一周之内是否已经找回过密码, 同一个ip一天之内之内找回3次密码 var t1 = dt.AddDays(-7); var gpl_uid = db.getpwdlog.Where(p => p.uid == user.id && p.log_time > t1).Count(); if (gpl_uid > 0) { return(Content("一个星期之内只能找回一次密码")); } var t2 = dt.AddHours(-24); var gpl_ip = db.getpwdlog.Where(p => p.ip_address.Equals(ip) && p.log_time > t2).Count(); if (gpl_ip >= 3) { return(Content("同一个ip地址一天之内只能找回3次密码")); } string newpwd = Tools.getRandomStr(); string res = Tools.SendEmail(u.email, "您的密码是:" + newpwd); // 失败返回错误信息 if ("发送成功".Equals(res)) { var chPwdLog = new getpwdlog() { uid = (Int32)user.id, ip_address = ip, nick_name = user.nick_name, log_time = dt }; db.getpwdlog.Add(chPwdLog); // 修改密码的日志 user.pwd = HashTools.SHA1_Hash(newpwd); db.SaveChanges(); // 修改密码 } return(Content(res)); } return(Content("用户名或者邮箱不正确")); } } catch (Exception ex) { return(Content("后台出现错误:" + ex.Message)); } } } return(Content("参数错误")); }
static SecretUuid() { #error Update GuidBytes declaration with your own guid, then remove this error line. GuidBytes = new byte[16] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; string GuidString = HashTools.GetString(GuidBytes); GuidString = GuidString.Substring(0, 8) + "-" + GuidString.Substring(8, 4) + "-" + GuidString.Substring(12, 4) + "-" + GuidString.Substring(16, 4) + "-" + GuidString.Substring(20, 12); Guid = new System.Guid("{" + GuidString + "}"); }
public void Update(Utilisateur user) { Utilisateur x = _userRepository.FindById(user.Id); if (!x.Password.Equals(user.Password)) { user.Password = HashTools.ComputeSha256Hash(user.Password); } _userRepository.Update(user); }
public void TestBytesSum() { string seq1 = "11111111"; string seq2 = "2222222F"; byte[] bin1 = HashTools.HexStringToByteArray(seq1); byte[] bin2 = HashTools.HexStringToByteArray(seq2); HashTools.BytesSum(bin1, bin2); Assert.IsTrue(HashTools.ByteArrayToHexViaLookup32(bin1) == "33333340"); }
/// <summary> /// Gets the hash. /// </summary> /// <param name="transformations">Transformations.</param> /// <returns>The hash.</returns> public static string ToHash(this IEnumerable <DocumentTypeTransformation> transformations) { if (transformations == null) { throw new ArgumentNullException(nameof(transformations)); } var c = transformations?.Select(t => t.From + "-" + t.To + "-" + t.Transformations.Select(t2 => t2.ToString())?.ToImplodedString())?.ToImplodedString(); return(HashTools.GetHash(c, HashTools.HashType.SHA1)); }
public void Update(Utilisateur u) { Utilisateur userBD = repo.FindById(u.Id); if (!userBD.Password.Equals(u.Confirmpwd)) { u.Password = HashTools.ComputeSha256Hash(u.Confirmpwd); u.Confirmpwd = HashTools.ComputeSha256Hash(u.Confirmpwd); } repo.Update(u); }
/// <summary> /// 管理员在后台修改用户的资料 /// </summary> /// <param name="u"></param> /// <returns></returns> public ActionResult updateUser(UserExt u) { if (u != null && u.id > 0) { if (u.id == 1 && (u.state == 0 || u.is_admin == false)) { return(Content("超级管理员的权限不能更改")); } var cur_user = (user)Session["user"]; if (u.pwd != null && u.pwd.Length >= 6) { if (u.id == 1 && cur_user.id != 1) { return(Content("超级管理员的密码不能更改")); } u.pwd = HashTools.SHA1_Hash(u.pwd); } else { u.pwd = u.oldpwd; } if (u.email != null && u.email.Length > 0) { if (u.reg_date == DateTime.MinValue) { return(Content("注册时间参数错误")); } reflectModel.setValues(u); try { var model = reflectModel.AutoCopyToBase <user, UserExt>(u); int res = EfExt.Update(model); if (res > 0) { return(Content("1")); } } catch (Exception ex) { return(Content(ex.Message)); } return(Content("修改失败")); } else { return(Content("邮箱不能为空")); } } return(Content("参数错误")); }
public void TestByteArrayLessThan() { string seq1 = "11111111"; string seq2 = "2222222F"; byte[] bin1 = HashTools.HexStringToByteArray(seq1); byte[] bin2 = HashTools.HexStringToByteArray(seq2); byte[] bin2copy = HashTools.HexStringToByteArray(seq2); Assert.IsTrue(HashTools.ByteArrayLessThan(bin1, bin2)); Assert.IsFalse(HashTools.ByteArrayLessThan(bin2, bin1)); Assert.IsFalse(HashTools.ByteArrayLessThan(bin2, bin2copy)); }
public void Update(User user) { // 2 cas : la personne a conservé le même mot de passe // soit elle a modifié => on doit crypter User x = _userRepository.Find(user.Id); if (!x.Password.Equals(user.Password)) { user.Password = HashTools.ComputeSha256Hash(user.Password); } _userRepository.Update(user); }
/// <summary> /// Gets the hash. /// </summary> /// <param name="documentType">Document type.</param> /// <returns>The hash.</returns> public static string ToHash(this Database.DocumentDb.Entities.DocumentType documentType) { if (documentType == null) { throw new ArgumentNullException(nameof(documentType)); } var c = documentType.Type + documentType.Indexes?.Select(i => i.From + "-" + (i.To == null ? "null" : ((int)i.To).ToString(Cultures.Invariant)) + "-" + i.IsRequired + "-" + i.Type).ToImplodedString() + documentType.Transformations?.Select(t => t.From + "-" + t.To + "-" + t.Transformations.Select(t2 => t2.ToString())?.ToImplodedString())?.ToImplodedString(); return(HashTools.GetHash(c, HashTools.HashType.SHA1)); }
internal bool Read(WzFileStream zs) { this.Items.Clear(); zs.Seek(this.Offset); int count = zs.Read4(true); for (int i = 0; i < count; i++) { WzArchiveItem item = null; WzArchiveItemType itemtype; string itemname = zs.StringPool.DirectoryRead(out itemtype, WzArchiveItemType.Reference); if (itemtype == WzArchiveItemType.Directory) { item = new WzDirectory(itemname); } else if (itemtype == WzArchiveItemType.File) { item = new WzFile(itemname, zs.KeyType) { Stream = zs.BaseStream }; } else { throw new InvalidDataException("Undefined item type : " + (int)itemtype); } item.Size = zs.Read4(true); item.Checksum = zs.Read4(true); uint offKey = HashTools.GenerateOffsetKey((uint)zs.Tell(), this.Archive.DataOffset, this.Archive.Hash); item.Offset = HashTools.DecryptOffsetHash(zs.Read4u(), offKey, this.Archive.DataOffset); if ((item.Offset + item.Size) > zs.Length) { return(false); } this.Add(item); } for (int i = 0; i < this.Items.Count; i++) { if (this.Items[i].Type == WzArchiveItemType.Directory) { (this.Items[i] as WzDirectory).Read(zs); } } return(true); }
public string Hash(string hashForAllHeaderFilesPossiblyInfluencingCompilation) { StringBuilder builder = new StringBuilder(); foreach (string str in this.Arguments) { builder.Append(str); } builder.Append(this.CompilerExecutable); builder.Append(this.SourceFile); builder.Append(hashForAllHeaderFilesPossiblyInfluencingCompilation); builder.Append(HashTools.HashOfFile(this.SourceFile)); return(HashTools.HashOf(builder.ToString())); }
public void TestMethodGetHashCode() { IHash hashToTest = new HashTools(SHA256.Create()); string result = hashToTest.GetHashCode("Toto"); if (result == "29808E1E493C7B9903F2BB94EA5ABE57ED8B35E38D247C271AFDDFE227CCC3E8") { //test success } else { //test fails } }
public UserDto CheckLogin(string email, string password) { string msg = "Erreur : identifiants incorrects !"; //hasher le mot de passe string cryptedPwd = HashTools.ComputeSha256Hash(password); //récupérer l'utilisateur qui a cet email UserDto u = FindByEmail(email); if (u == null || !u.Password.Equals(cryptedPwd)) { throw new Exception(msg); } return(u); }