private DokuAuthUser _UserAdd(DokuAuthUser user) { DokuAuthUser userexist = this._userList.SingleOrDefault(o => o.Login.Equals(user.Login)); if (userexist == null) { if ( (string.IsNullOrWhiteSpace(user.Password)) && (string.IsNullOrWhiteSpace(user.PasswdHash)) ) { return(default(DokuAuthUser)); } user.PasswdHash = ((string.IsNullOrWhiteSpace(user.PasswdHash)) ? CryptUtils.Crypt(user.Password) : user.Password); user.Group = ((string.IsNullOrWhiteSpace(user.Group)) ? ((string.IsNullOrWhiteSpace(this._group)) ? groupDefault : this._group) : user.Group ); this._userList.Add(user); userexist = user; } else { userexist.Name = user.Name; userexist.Email = user.Email; userexist.Group = ((string.IsNullOrWhiteSpace(user.Group)) ? userexist.Group : user.Group); userexist.PasswdHash = ((string.IsNullOrWhiteSpace(user.PasswdHash)) ? ((string.IsNullOrWhiteSpace(user.Password)) ? userexist.PasswdHash : CryptUtils.Crypt(user.Password)) : user.PasswdHash ); } this._isChanged = true; return(userexist); }
public void Crypt_Sha256() { Assert.AreEqual("$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5", CryptUtils.Crypt("Hello world!", "$5$saltstring")); Assert.AreEqual("$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12oP84Bnq1", CryptUtils.Crypt("a very much longer text to encrypt. This one even stretches over morethan one line.", "$5$rounds=1400$anotherlongsaltstring")); }
public void Crypt_Sha512() { Assert.AreEqual("$6$88YzdOoo$L1eCUeaJ914gHjxGToexJOeUbTxV89yWuDPEWxeSmI7pJowq2HMaWWvCcISDTt1p51Ui9YhkKhCVy5EsMeEnu.", CryptUtils.Crypt("temp123", "$6$88YzdOoo")); Assert.AreEqual("$6$rounds=1400$anotherlongsalts$POfYwTEok97VWcjxIiSOjiykti.o/pQs.wPvMxQ6Fm7I6IoYN3CmLs66x9t0oSwbtEW7o7UmJEiDwGqd8p4ur1", CryptUtils.Crypt("a very much longer text to encrypt. This one even stretches over morethan one line.", "$6$rounds=1400$anotherlongsaltstring")); }
public void Crypt_And_MakeSalt() { string salt = CryptUtils.MakeSalt(); string hash = CryptUtils.Crypt("temp321", salt); Assert.Greater(hash.Length, 106); Assert.True(salt.Contains("rounds=")); Assert.That(hash.StartsWith(salt + "$")); Assert.AreEqual(3, SplitHash(hash).Length); }
public void Crypt_Md5() { Assert.AreEqual("$1$saltstri$YMyguxXMBpd2TEZ.vS/3q1", CryptUtils.Crypt("Hello world!", "$1$saltstring")); }