hash

Correct way of creating salted hash password

淺唱寂寞╮ 提交于 2019-12-22 17:29:20
问题 I am new to storing passwords on databases and from what I read I have created a simple php script below <?php $salt = openssl_random_pseudo_bytes (16); $password = "test"; $hash = hash ("sha512" , $salt . $password); echo $hash; ?> Am I doing this correctly? Should the salt be stored in databases as byte datatype? Should the final hash be stored at String datatype in database? 回答1: The SHA* algorithms are not appropriate to hash passwords, because they are ways too fast, and therefore can be

sort keys in hash of array by the number of elements in the array

人走茶凉 提交于 2019-12-22 12:51:37
问题 I have a hash of arrays. %HoA = ( 'C1' => ['1', '3', '3', '3'], 'C2' => ['3','2'], 'C3' => ['1','3','3','4','5','5'], 'C4' => ['3','3','4'], 'C5' => ['1'], ); The values in the array don't matter per se. I would like to sort the keys by the size of the array in descending order. The output should look like. C3 # this key contains an array with the most elements C1 C4 C2 C5 # this key contains an array with the least elements I don't know why this isn't working. foreach my $key ( sort { $HoA{

sort keys in hash of array by the number of elements in the array

安稳与你 提交于 2019-12-22 12:49:08
问题 I have a hash of arrays. %HoA = ( 'C1' => ['1', '3', '3', '3'], 'C2' => ['3','2'], 'C3' => ['1','3','3','4','5','5'], 'C4' => ['3','3','4'], 'C5' => ['1'], ); The values in the array don't matter per se. I would like to sort the keys by the size of the array in descending order. The output should look like. C3 # this key contains an array with the most elements C1 C4 C2 C5 # this key contains an array with the least elements I don't know why this isn't working. foreach my $key ( sort { $HoA{

Group a Ruby Array of Dates by Month and Year into a Hash

江枫思渺然 提交于 2019-12-22 12:33:55
问题 Let's say I had a Ruby Array of Date s like: 2011-01-20 2011-01-23 2011-02-01 2011-02-15 2011-03-21 What would be an easy and Ruby-esque way of creating a Hash that groups the Date elements by year and then month, like: { 2011 => { 1 => [2011-01-20, 2011-01-23], 2 => [2011-02-01, 2011-02-15], 3 => [2011-03-21], } } I can do this by iterating over everything and extracting years, months and so on, then comining them. Ruby offers so many methods and blocks for Arrays and Hashes, there must be

Group a Ruby Array of Dates by Month and Year into a Hash

心不动则不痛 提交于 2019-12-22 12:33:13
问题 Let's say I had a Ruby Array of Date s like: 2011-01-20 2011-01-23 2011-02-01 2011-02-15 2011-03-21 What would be an easy and Ruby-esque way of creating a Hash that groups the Date elements by year and then month, like: { 2011 => { 1 => [2011-01-20, 2011-01-23], 2 => [2011-02-01, 2011-02-15], 3 => [2011-03-21], } } I can do this by iterating over everything and extracting years, months and so on, then comining them. Ruby offers so many methods and blocks for Arrays and Hashes, there must be

Existing data serialized as hash produces error when upgrading to Rails 5

…衆ロ難τιáo~ 提交于 2019-12-22 11:35:25
问题 I am currently upgrading a Ruby on Rails app from 4.2 to 5.0 and am running into a roadblock concerning fields that store data as a serialized hash. For instance, I have class Club serialize :social_media, Hash end When creating new clubs and inputting the social media everything works fine, but for the existing social media data I'm getting: ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be a Hash, but was a ActionController::Parameters. How can I convert all of the

Existing data serialized as hash produces error when upgrading to Rails 5

非 Y 不嫁゛ 提交于 2019-12-22 11:35:17
问题 I am currently upgrading a Ruby on Rails app from 4.2 to 5.0 and am running into a roadblock concerning fields that store data as a serialized hash. For instance, I have class Club serialize :social_media, Hash end When creating new clubs and inputting the social media everything works fine, but for the existing social media data I'm getting: ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be a Hash, but was a ActionController::Parameters. How can I convert all of the

Datastructures, C#: ~O(1) lookup with range keys?

别来无恙 提交于 2019-12-22 11:34:06
问题 I have a dataset. This dataset will serve a lookup table. Given a number, I should be able to lookup a corresponding value for that number. The dataset (let's say its CSV) has a few caveats though. Instead of: 1,ABC 2,XYZ 3,LMN The numbers are ranges (- being "through", not minus): 1-3,ABC // 1, 2, and 3 = ABC 4-8,XYZ // 4, 5, 6, 7, 8 = XYZ 11-11,LMN // 11 = LMN All the numbers are signed ints. No ranges overlap with another ranges. There are some gaps; there are ranges that aren't defined in

Validate NT and LM hashes against Active Directory

流过昼夜 提交于 2019-12-22 10:59:34
问题 I'm writing web-application authenticating user using NTLM protocol. I have successfully get password's NT and LM hashes from client. How I can validate them against Active Directory to ensure that password is correct. I'm using C#, but I think it will be possible for me to call native library as well. EDIT : I don't see reason for down-votes. NTLM(v2) protocol is outdated so it's really hard to find relative information on how to handle it. Especially from within such a modern language as C#

Is there a keyed SHA256 hash algorithm that is FIPS compliant for .NET?

假装没事ソ 提交于 2019-12-22 10:56:08
问题 I am creating a keyed SHA256 hash using HMACSHA256 with the following code: HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secretKey); byte[] hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(data)); string hashResult = string.Empty; for (int i = 0; i < hash.Length; i++) { hashResult += hash[i].ToString("x2"); // hex format } This is working just fine, however, it fails in a FIPS enabled environment because HMACSHA256 uses an underlying SHA256Managed implementation which is itself not