Exemplo n.º 1
0
        /// <summary>
        /// Populates the administrators table.
        /// </summary>
        public static void Administrators()
        {
            // Delete all the administrators
            unitOfWork.Administrators.Entities.ToList().ForEach(admin =>
            {
                unitOfWork.Accounts.Remove(admin.Account);
                unitOfWork.Addresses.Remove(admin.Person.Address);
                unitOfWork.Persons.Remove(admin.Person);
                unitOfWork.Administrators.Remove(admin);
            });

            // Add all the administrators
            unitOfWork.Administrators.Add(new Administrator
            {
                Person = new Person
                {
                    FirstName = "Mihai",
                    LastName  = "Nitu",
                    BirthDate = new DateTime(1979, 7, 20),
                    Gender    = unitOfWork.Genders.Entities.First(g => g.Type == "Male"),
                    Nin       = "1790720425218",
                    PhoneNo   = "+(40) 727 109 531",
                    Address   = new Address
                    {
                        County   = unitOfWork.Counties.Entities.First(c => c.Name == "București"),
                        City     = "București",
                        Street   = "Remus",
                        StreetNo = "7",
                        ZipCode  = "030167"
                    },
                },
                Account = new Account
                {
                    Email    = "*****@*****.**",
                    Password = BCrypt.HashPassword("nitu1234")
                },
                IsOwner = true,
                Active  = true
            });

            VivusConsole.WriteLine($"Admnistrators: { unitOfWork.Complete() }");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns account with given name, or null if it doesn't exist.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Account GetAccount(string name)
        {
            using (ISession session = SessionFactory.OpenSession())
            {
                var account = session.Query <Account>()
                              .Where(x => x.Name == name)
                              .FirstOrDefault();

                if (account != null)
                {
                    // Upgrade MD5 hashes
                    if (account.Password.Length == 32)
                    {
                        account.Password = BCrypt.HashPassword(account.Password, BCrypt.GenerateSalt());
                    }
                }

                return(account);
            }
        }
        public string DoGenerateBcrypt(string password, string salt, int cost)
        {
            this.error.cleanError();
            if (!areBCryptValidParameters(password, salt, cost))
            {
                return("");
            }
            EncodingUtil eu = new EncodingUtil();

            byte[] encryptedBytes = BCrypt.Generate(eu.getBytes(password), Hex.Decode(salt), cost);
            string result         = Base64.ToBase64String(encryptedBytes);

            if (result == null || result.Length == 0)
            {
                this.error.setError("PD010", "Brypt generation error");
                return("");
            }
            this.error.cleanError();
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Populates the donation centers personnel table.
        /// </summary>
        public static void DonationCentersPersonnel()
        {
            // Delete all the donation centers personnel
            unitOfWork.DCPersonnel.Entities.ToList().ForEach(personnel =>
            {
                unitOfWork.Accounts.Remove(personnel.Account);
                unitOfWork.Addresses.Remove(personnel.Person.Address);
                unitOfWork.Persons.Remove(personnel.Person);
                unitOfWork.DCPersonnel.Remove(personnel);
            });

            // Add all the donation centers personnel
            unitOfWork.DCPersonnel.Add(new DCPersonnel
            {
                Person = new Person
                {
                    FirstName = "Daniel",
                    LastName  = "Moldovan",
                    BirthDate = new DateTime(1980, 11, 4),
                    Gender    = unitOfWork.Genders.Entities.First(g => g.Type == "Male"),
                    Nin       = "1801104123318",
                    PhoneNo   = "+(40) 722 129 315",
                    Address   = new Address
                    {
                        County   = unitOfWork.Counties.Entities.First(c => c.Name == "Cluj"),
                        City     = "Cluj-Napoca",
                        Street   = "Slatina",
                        StreetNo = "2",
                        ZipCode  = "400000"
                    },
                },
                Account = new Account
                {
                    Email    = "*****@*****.**",
                    Password = BCrypt.HashPassword("moldovan")
                },
                Active = true
            });

            VivusConsole.WriteLine($"Donation Centers Personnel: { unitOfWork.Complete() }");
        }
Exemplo n.º 5
0
        public bool Login(string userName, string passWord)
        {
            var result = db.Users.SingleOrDefault(x => x.UserName == userName);

            if (result == null || result.Deleted || result.Status == false)
            {
                return(false);
            }
            else
            {
                bool isValidated = BCrypt.CheckPassword(passWord, result.Password);
                if (isValidated)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Exemplo n.º 6
0
    // Token: 0x0600024A RID: 586 RVA: 0x00011B3C File Offset: 0x0000FD3C
    private IntPtr method_3(IntPtr intptr_0, byte[] byte_0, out IntPtr intptr_1)
    {
        byte[] value  = this.oaijRxoMrH(intptr_0, BCrypt.BCRYPT_OBJECT_LENGTH);
        int    num    = BitConverter.ToInt32(value, 0);
        IntPtr intPtr = Marshal.AllocHGlobal(num);

        byte[] array = this.method_4(new byte[][]
        {
            BCrypt.BCRYPT_KEY_DATA_BLOB_MAGIC,
            BitConverter.GetBytes(1),
            BitConverter.GetBytes(byte_0.Length),
            byte_0
        });
        uint num2 = BCrypt.BCryptImportKey(intptr_0, IntPtr.Zero, BCrypt.BCRYPT_KEY_DATA_BLOB, out intptr_1, intPtr, num, array, array.Length, 0U);

        if (num2 > 0U)
        {
            throw new CryptographicException(string.Format("BCrypt.BCryptImportKey() failed with status code:{0}", num2));
        }
        return(intPtr);
    }
Exemplo n.º 7
0
        public void updateUser()
        {
            addUser();

            string pw   = "password1" + vars.staticSalt;
            string salt = BCrypt.GenerateSalt();
            string hash = BCrypt.HashPassword(pw, salt);

            Hashtable ht = new Hashtable();

            ht.Add("username", "admin1");
            ht.Add("password", hash);
            ht.Add("fName", "John2");
            ht.Add("midName", "Dee2");
            ht.Add("lName", "Doe2");
            ht.Add("email", "*****@*****.**");
            ht.Add("address", "Philippines2");
            ht.Add("gender", "F");

            string c = (false) ? "Y" : "N";

            ht.Add("deactivated", c);
            ht.Add("picLocation", @"c:\piclocation\pic2.img");
            ht.Add("role", convertRole.role("User"));
            ht.Add("updatedBy", 0);

            Check_up.classes.Users user = new Users();
            Assert.IsTrue(user.updateUser(ht));

            string           sql = "select * from users";
            DataTable        dt  = new DataTable();
            MySqlCommand     cmd = new MySqlCommand(sql, vars.MySqlConnection);
            MySqlDataAdapter da  = new MySqlDataAdapter(cmd);

            da.Fill(dt);

            Assert.AreEqual(dt.Rows[0]["username"], "admin1");
            Assert.AreEqual(dt.Rows[0]["fName"], "John2");
        }
Exemplo n.º 8
0
 public IActionResult Login(ViewModels.LoginModel model)
 {
     Contract.Assert(model != null);
     if (ModelState.IsValid)
     {
         Models.User user = database.Users.Include(x => x.Roles).FirstOrDefault(u => u.Login == model.Login);
         if (user == null || !BCrypt.Generate(Encoding.Unicode.GetBytes(model.Password), salt, 8).SequenceEqual(user.PasswordHash))
         {
             ModelState.AddModelError("", "Неверный логин или пароль");
         }
         else
         {
             Authenticate(user).ConfigureAwait(false);
             return(RedirectToAction("Index", "Home"));
         }
     }
     else
     {
         ModelState.AddModelError("", "Неправильно введены данные");
     }
     return(View(model));
 }
Exemplo n.º 9
0
        public dynamic LogInPost(dynamic parameters)
        {
            var username = (string)this.Request.Form.username;
            var password = (string)this.Request.Form.password;

            var user = this.botUserConfiguration.Items.FirstOrDefault(x => x.Identifier == "$a:" + username);

            if (user != null)
            {
                if (BCrypt.Verify(password, user.WebPassword))
                {
                    var token = user.WebGuid;
                    return(this.LoginAndRedirect(token));
                }
            }

            var loginDataModel = this.CreateModel();

            loginDataModel.Error    = "Invalid username or password";
            loginDataModel.Username = username;
            return(loginDataModel);
        }
Exemplo n.º 10
0
    /// <summary>
    /// Hash a password using the OpenBSD bcrypt scheme.
    /// </summary>
    /// <param name="password">The password to hash.</param>
    /// <param name="salt">The salt to hash with (perhaps generated
    /// using <c>BCrypt.GenerateSalt</c>).</param>
    /// <returns>The hashed password.</returns>
    public static string HashPassword(string password, string salt)
    {
        if (password == null)
        {
            throw new ArgumentNullException("password");
        }
        if (salt == null)
        {
            throw new ArgumentNullException("salt");
        }

        char minor = (char)0;

        if (salt[0] != '$' || salt[1] != '2')
        {
            throw new ArgumentException("Invalid salt version");
        }

        int offset;
        if (salt[1] != '$')
        {
            minor = salt[2];
            if (minor != 'a' || salt[3] != '$')
            {
                throw new ArgumentException("Invalid salt revision");
            }
            offset = 4;
        }
        else
        {
            offset = 3;
        }

        // Extract number of rounds
        if (salt[offset + 2] > '$')
        {
            throw new ArgumentException("Missing salt rounds");
        }

        int rounds = Int32.Parse(salt.Substring(offset, 2), NumberFormatInfo.InvariantInfo);

        byte[] passwordBytes = Encoding.UTF8.GetBytes(password + (minor >= 'a' ? "\0" : String.Empty));
        byte[] saltBytes = DecodeBase64(salt.Substring(offset + 3, 22),
                                        BCRYPT_SALT_LEN);

        BCrypt bcrypt = new BCrypt();

        byte[] hashed = bcrypt.CryptRaw(passwordBytes, saltBytes, rounds);

        StringBuilder rs = new StringBuilder();

        rs.Append("$2");
        if (minor >= 'a')
        {
            rs.Append(minor);
        }
        rs.Append('$');
        if (rounds < 10)
        {
            rs.Append('0');
        }
        rs.Append(rounds);
        rs.Append('$');
        rs.Append(EncodeBase64(saltBytes, saltBytes.Length));
        rs.Append(EncodeBase64(hashed,
                               (bf_crypt_ciphertext.Length * 4) - 1));

        return rs.ToString();
    }