FAQ Database Discussion Community


C++: Quickest way to get integer within a range

c++,c,hash,modulo,low-latency
I need to generate hash keys for about N=100 million keys. From my study it appears that murmur3 (MurmurHash3_x86_32, see murmur3 hash) would be the fastest hashing function with best latency and small enough collision rate. The problem I am facing is that the function returns key as void *....

Hashing Password in ASP.NET and Resolving it In SQL Procedure

asp.net,vb.net,stored-procedures,hash,password-protection
I'm developing an ASP.NET application using SQL Server Stored Procedures. I need to hash my login password and resolve it in my sp_LoginCheck Stored Procedure. Any suggestions? I have already inserted data in the database. For example: UserName/Password ABC/123456 DEF/987654 I want to encrypt or hash whatsoever the password then...

How to write a hash function for a std::vector>

c++,hash,struct,stl,unordered-set
I have a struct which has one variable, a std::vector<std::vector<bool>> that represents a grid. One of these structs is equal to another if the grids are equal, or if any rotation of the grids is equal. I'm trying to use an unordered_set to store many of these, however, after some...

How can I generate the same secure hash in Java and Ruby using PBKDF2

java,ruby,hash,pbkdf2
I am porting a web application from Ruby to Java and would like to allow the users to log in without resetting their passwords. Here is the Ruby code that generates the hash using the pbkdf2 gem: PBKDF2.new { |p| p.password = password p.salt = salt p.iterations = 10000 }.hex_string...

How can I get the original type of data after being processed by Object as Hash in JavaScript?

javascript,object,hash
LeetCode 136 Single Number Given an array of integers, every element appears twice except for one. Find that single one. I have solved this problem by using Object-property in JS as Hash. However, the property only allows string type, so all the data are automatically converted to string. var singleNumber...

Remove an item from each hash in an Array of hashes

arrays,ruby,hash
I have an array of hashes like this: array = [{ "id"=>"ABC", "account"=>"XYZ", "date"=>"2014-07-21", "amount"=>200, "score"=>{"location"=>{"city"=>1, "state"=>1}, "name"=>1}, "cat"=>#<Tipper::Category:0xb666fb0 @type={"primary"=>"special"}, @hierarchy=["Transfer","Withdrawal", "ATM"], @id="21012002" >, "state"=>"CA" }, {"id=>"XYZ","account"=>"987"}] I want to iterate through each hash in the array and remove the "category" piece from each hash and produce an array of...

change value in hash using an array of keys in ruby

arrays,ruby,hash
i was wondering if it is possible to access an value of a hash with an array of keys as described in the post ruby use array tvalues to index nested hash of hash. My aim is not just to access this value but to change this value. As I...

choice between map or unordered_map for keys consisting of calculated double values.

c++,dictionary,hash,unordered-map,comparison-operators
In order to quickly find coplanar entities in a bunch of planar entities in 3d space, I want to create a mapping from 3d planes to the set of entities lying in that plane (estimated max around ~1000 planes and ~100000 entities) I can create my own custom class to...

Formating issue with md5deep

batch-file,hash,md5
So I am making a program in batch and it requires a text file to be hashed then the hash has to be saved to a text file. I already have that part done but when it saves to the text file it saves like this f558e01b798b0390ab6206679a6926a7 C:\Users\computer\Desktop\tmpfile.txt So my...

How to generate a md5 hash for an htpasswd file in PHP when I don't have the plaintext

php,linux,apache,encryption,hash
I have records in my database for users passwords encrypted with md5. I'd like to have PHP add those encrypted passwords to the htpasswd file. But I've read that the htpasswd file uses an MD5 algorithm that is repeated 1000 times and salted. I've found plenty of examples online for...

How to correctly dereference a hash within a foreach loop?

perl,hash
I would like to print the contents of a hash that I have created in the following way: $dataStore{"$items1"}{"$items2"}{"$items3"}{'counts'}[0] = 534; Edit: I forgot to add that the variables above are being read in from a file within a while loop, but I left it out since that works correctly...

Reference RSVP hash from inside the same hash

ember.js,hash
I'm trying to load two different models on the same route, I found a stack overflow that explained I can use Ember.RSVP.hash() to get this done, here is what I've done to make it work. model: function(params) { return Ember.RSVP.hash({ flyer: this.store.find('flyer', params.flyer_id), images: this.store.find('image', '-Jrgar1tSArUw-_PiJqX') }); }, As you...

Applying Hash Function n times

c,hash
I need to implement the iterative aplication of the certain hash function for example SHA1 with input x n times, efficiently, i.e SHA1(...SHA1(SHA1(x))). I'm trying to make this with the code below but this so slow 2 sec for n=2^16. In the code below $n$ is the number of times...

PHP: Password Hashing

php,hash
I've started using the password_hash() for password hashing. The problem I'm having is that when I use the password_verify() to check if input value matches the hashed passwords stored in the database, every time it returns me false. $password = "test"; $query = "SELECT password FROM user WHERE password =...

Assign hash to array

arrays,ruby,file,hash
My goal is create a hash that stores values from an array as the keys and gets values from another array as the values. I would like to relate "i" value from one array to "i" value from another array. My first array stores the name of files and second...

Java Hashing Password Doesn't Match

java,string,hash
After searching in Google and watching a few posts in StackOverflow ( Java hashing passwords , Hashing Password ). I try not to duplicate questions and looking for the answers by myself, but as you can appreciate, this was not the case. I'm creating a simple library in Java to...

Perl - Hash and the => operator

perl,hash
So Im learning Perl and got to the chapter about hashes. I understand that the '=>' operator is an alias to the comma operator. But when I try to make a value undef I get the warning Use of uninitialized value $last_name{"dino"} in concatenation (.) or string at ./learning.pl line...

Java HashMap, hashCode() equals() - how to be consistent with multiple keys? [duplicate]

java,hash,hashmap,key
This question already has an answer here: What issues should be considered when overriding equals and hashCode in Java? 12 answers I have an ID class. It refers to identification for a unique person. There are two forms of ID. Username and user number. If either username matches or...

How to dig into an certain hash depth?

perl,hash
I have a hash where I don't know its depth. I got it with DBI::selectall_hashref where the second parameter is given by the user. So depending on the query I can have something like this for a 2-levels hash. hash_ref = ( aphrodite => ( foo => ( name =>...

How does hopscotch hashing actually work?

algorithm,performance,hash,hashtable,hopscotch-hashing
I am reading about hopscotch hashing The algorithm says when we run into colision during insert: Otherwise, j is too far from i. To create an empty entry closer to i, find an item y whose hash value lies between i and j, but within H − 1 of j,...

Merge ruby hashes adding keys

ruby,hash
I have two hashes with the same keys {1=>2, 2=>450, 3=>3} and {1=>'1232', 2=>'ffsa', 3=>'vdsvds'} I want to merge them to this { 1=> {:number => 2, :string => '1232'}, 2=>{:number => 450, :string => 'ffsa'}, 3=>{:number => 3, :string => 'vdsvds'} } getting values for subkey 'number' from the...

Error Hashing + Salt password

python,authentication,python-3.x,hash,salt
Someone can help me to fix this problem: TypeError: can't concat bytes to str I am trying to safely store hash+salt passwords, I think the problem is that my salt is a byte object how can I transform it into a string? Or is there a way to hash it...

Sorting a hash in Perl when the keys are dynamic

perl,sorting,hash
I have a hash as follows: my %data = ( 'B2' => { 'one' => { timestamp => '00:12:30' }, 'two' => { timestamp => '00:09:30' } }, 'C3' => { 'three' => { timestamp => '00:13:45' }, 'adam' => { timestamp => '00:09:30' } } ); (The structure is...

Output for merged array of hashes

arrays,ruby,hash
Hopefully this isn't a dupe, but I wasn't able to find a specific answer. I have to arrays of hashes: a1 = [{"aws_ebs_stripe"=>"/dev/xvdi"}, {"aws_ebs_stripe"=>"/dev/xvdj"}, {"aws_ebs_stripe"=>"/dev/xvdk"}, {"aws_ebs_stripe"=>"/dev/xvdl"}] a2 = [{"volume_id"=>"vol-001011"}, {"volume_id"=>"vol-010110"}, {"volume_id"=>"vol-101101"}, {"volume_id"=>"vol-011001"}] I'm combining these with some code I found earlier Hash[a1.zip(a2.map { |i| i.include?(',') ? (i.split /, /) :...

to access a specific key-value pair in hash

perl,hash
I want to print only the specific key:pair from the following hash in perl: 1: one 2: two 3: three and I am using the following statement to print my hash: foreach (sort keys %hash) { print "$_ : $hash{$_}"; } what should the code if I only want to...

HMAC + SHA256 jwt secret length

hash,cryptography,jwt
I will be signing a token with SHA256 and I am wondering on the length of the secret I should put. Does having a secret key length over 256 bits have any benefits if I am using sha256. So if my key is 300 bits long is this more secure?

Element is present but `Set.contains(element)` returns false

java,hash,set,contains,hashset
How can an element not be contained in the original set but in its unmodified copy? The original set does not contain the element while its copy does. See image. The following method returns true, although it should always return false. The implementation of c and clusters is in both...

custom sort method for hashes which will automatically use the approporiate hash

perl,sorting,hash
My hash contains binary numbers as keys: my %h = ("1010" => 1, "1110" => 0, "0001" => 3, "1100" => 2); In perl I can use custom function for sorting hash. This is my function for sorting binary numbers from lowest to largest: sub sort_binary_numbers { my $a_dec =...

Rails hash key/value created differently in local vs heroku

ruby-on-rails,postgresql,sqlite,heroku,hash
I ran into this issue late last night and I just figured out what happened, but I want to understand why. I tested my code in my local (using sqlite) and it worked fine, but when I deployed to heroku (postgres), a summary table was not showing the right results....

What is Fragment URLs and why to use it

php,url,hash,fragment-identifier
I am new in PHP Development. Today I came across the interesting topic URL fragmentation specifically the '#' part of the URLs. I searched about that It says it's like www.example.com\foo.html#bar. But I don't understand why this "#bar" is needed. and how to read it by PHP?...

how to match hash values in two different hashes

ruby,hash
I am trying to count the number of matching appid in two separate hashes, but my solution feels clunky. Can someone suggest a 'ruby' way of doing this? #hash from an array: {"appid"=>240, "playtime_forever"=>103} {"appid"=>2670, "playtime_forever"=>1099} #This is Steam data for those interested def games_in_common(friend_hash,other_hash) arr1=Array.new arr2=Array.new other_hash.keys.each{|k| arr1<<other_hash[k] }...

PHP Compare a crypted password from db with an inserted password from a form

php,hash,cryptography,passwords,md5
I've a db with crypted password. When a user logs in, i make this: $result = mysqli_fetch_assoc(mysqli_query($conn,$query)); $cryptedPass = $result['password']; $pass = $_POST['password']; if(strcmp($cryptedPass,md5($pass))==0) echo "yeah!"; It works, but I would like to know if this the right manner, or if there is something of safer!...

Ruby access hash within an array within a hash (and add new hash)

arrays,ruby,hash
I'm new to Ruby and still learning about hashes. I've tried looking here for other similar answers but wasn't able to find anything that completely answered my question. I have some data stored in a hash structure that I'm feeding into a script that updates a Neo4j database ( so...

Bulk Password Hashing PHP-LOGIN PROJECT code

php,mysql,pdo,hash
I have the following question / requirement. My website has 2000 users, however the passwords are stored using Plain text (I know this is super bad). From reading various website blogs, i found that i need to use modern password-hashing and salting. I found php-login.net . They use modern salting...

Change password function not working - hash wrong

cakephp,authentication,hash,passwords
Ok, I've been hitting my head against this wall all evening. Can someone explain to my why this returns false (user model): public function changePassword($user_id, $currentPassword, $newPassword, $repeatPassword){ //Check repeat /* if($newPassword != $repeatPassword) return false; */ //Check old password $this->id = $user_id; $current = $this->field('password'); $passwordHasher = new BlowfishPasswordHasher();...

Save the most recent months of a hash

ruby-on-rails,arrays,ruby,hash
I have an array of hashes. Something like this... transactions = [{"date"=>"2014-07-21", "amount"=>200}, {"date"=>"2012-06-21", "amount"=>400}, {"date"=>"2014-08-21", "amount"=>100}, {"date"=>"2014-08-12", "amount"=>150}, {"date"=>"2014-06-15", "amount"=>230} {"date"=>"2013-05-21", "amount"=>900},] I want to be able to save each months total amounts and then show the most recent 3 months to todays date and their total amount. Something...

generating a pseudo unique number(code) based on a sequence of numbers with no repetition within 4 digits

php,math,hash
I'm generating a somewhat unique code that I don't want to repeat within at least 1000 consecutive numbers this is my function. take a number multiply it by another number then take the last $length=5 digits before the decimal point function createPseudoUniqueString($input,$length) { return substr( intval($input*738510.93067),-$length) ; } is there...

Ruby on Rails Hash#slice method returns empty hash

ruby-on-rails-4,hash,slice,ruby-2.0,activesupport
Why does the first example return a hash with the two specified keys, while the second example returns an empty hash? User.last.slice(:created_at, :updated_at) => {"created_at"=>Fri, 22 May 2015 00:33:37 UTC +00:00, "updated_at"=>Fri, 22 May 2015 01:00:06 UTC +00:00} User.last.attributes.slice(:created_at, :updated_at) => {} Notice the the difference in the examples is...

NSData dataWithContentsOfFile returns different results on device

ios,iphone,hash,md5,nsdata
I'm using dataWithContentsOfFile on a PNG image and the iOS Simulator returns a value that differs from an iOS Device. My device is a 64-bit iPad Air (iOS 8.3) and my simulator is set to iPad Retina iOS 8.3. Here's the code that I'm using: NSString *sourcePath = [[NSBundle mainBundle]...

HashMap - contains and get methods should not be used together

java,algorithm,dictionary,hash,hashmap
I got the following question from an interview. I was given a character array like this: char[] characters = {'u', 'a', 'u', 'i', 'o', 'f', 'u'}; I needed to get the distinct characters and counts of each character: u = 3 a = 1 i = 1 o = 1...

Get array of values from array of hashes

ruby,hash
I have a array like this arr = [{:id=>1}, {:id=>2}, {:id=>3}, {:id=>4}, {:id=>5}, {:id=>6}, {:id=>7}, {:id=>8}] The result should be result = [1, 2, 3, 4, 5, 6, 7, 8] I used arr.map { |i| i.values }.However, the result is [[1], [2], [3], [4], [5], [6], [7], [8]]. Please help....

Hash Map entries collision

java,eclipse,dictionary,hash,hashmap
I am trying this code snippet Map headers=new HashMap(); headers.put("X-Capillary-Relay","abcd"); headers.put("Message-ID","abcd"); Now when I do a get for either of the keys its working fine. However I am seeing a strange phenomenon on the Eclipse debugger. When I debug and go inside the Variables and check inside the table entry...

Unable to understand the hash function of Rabin Karp Algorithm explained at topcoder

algorithm,hash,rabin-karp
I was reading the Rabin Karp Algorithm at Topcoder. But in that article, I am not able to get the following hash evaluation. // calculate the hash value of the first segment // of the text of length m ht = 0; for(i = 0; i < m; i++) ht...

Hashing speed - cryptic results (Hashing twice much slower than hashing once)

c#,.net,hash
I'm trying to understand why hashing of multiple hashes is much slower than one hash. In the following test I hash a file twice - first with SHA1 and then with both SHA1 and SHA256. The first execution shows the expected results - disk read dominates the time used -...

What will happen if they changed PASSWORD_DEFAULT in PHP Password library?

php,hash,passwords,php-password-hash
Consider this line of code by using PHP: $password = password_hash($password, PASSWORD_DEFAULT); What will happen if they changed the default password hashing algorithm? I mean I will be having hashed password inside the database. Then, from my own understanding, it will be impossible to check the password because the hashing...

Perl comparing two hashes

perl,hash,compare
I am a beginner with Perl, and am trying to write a script to compare the two hashes and print the values in the first hash that are not found in the second. Although I know the script should be very simple, I am not sure why mine is not...

Decoding Hash from JSON-String in Perl

json,perl,hash
Why does this not work? my $myHashEncoded = encode_json \%myHash; my %myHashDecoded = decode_json($myHashEncoded); I get the error: Reference found where even-sized list expected at ... So I changed it to: my $myHashEncoded = encode_json \%myHash; my $myHashDecoded = decode_json($enableInputEncoded); But then obviously %myHash is not the same as $myHashDecoded....

Why does my first hash value disappear in Perl?

arrays,perl,hash
Why does the hash remove the first value apple:2 when I print the output? use warnings; use strict; use Data::Dumper; my @array = ("apple:2", "pie:4", "cake:2"); my %wordcount; our $curword; our $curnum; foreach (@array) { ($curword, $curnum) = split(":",$_); $wordcount{$curnum}=$curword; } print Dumper (\%wordcount); ...

Convert md5 in base64 in md5 of 32 characters with PHP

php,hash,md5
I have an example: Md5 base64: wPE2JkrsTJxF+KbSDApwYQ== Md5 using md5_file: c0f136264aec4c9c45f8a6d20c0a7061 how convert the firts md5 in the second md5?...

How can I delete duplicate values from a hash of hash

ruby,ruby-on-rails-4,hash
I need a unique hash , where the value of "one" should never repeat. for example, hash= {"1"=>{"one"=>1,"two"=>2}, "2"=>{"one"=>1,"two"=>3}, "3"=>{"one"=>2,"two"=>3}, "4"=>{"one"=>1,"two"=>2}} then the result should be, hash= {"1"=>{"one"=>1,"two"=>2}, "3"=>{"one"=>2,"two"=>3}} ...

How to print value of a hash map according to increasing/decreasing order of key in c++? [on hold]

c++,hash,hashmap
If we have a map, map <int,int> m; and following key value pair (-2,3) , (-14,8) , (4,8), (6,12) , (3,76) Now if we want to print value in increasing order of keys,then how to print ? o/p 8 3 76 8 12...

Deriving a variable type based on another variable type in C++

c++,templates,hash
I'm working on the implementation of hash functions, mainly based on the Carter and Wegman trick. Based on the size of the input space, the prime used needs to be long enough to make a robust hash, e.g. if I want a hash for uint32_t, I'll use the Mersenne prime...

Why is the cost of a hash lookup O(1) when evaluating the hash function might take more time than that?

hash,hashtable,big-o,time-complexity
A HashMap (or) HashTable is an example of keyed array. Here, the indices are user-defined keys rather than the usual index number. For example, arr["first"]=99 is an example of a hashmap where theb key is first and the value is 99. Since keys are used, a hashing function is required...

How to generate a Facebook Release Key Hash on Mac?

android,facebook,osx,hash,facebook-sdk-3.0
I am trying to generate a release key hash for my Android app, following the Facebook docs, I have no problem creating the debug with: keytool -exportcert -alias plicprintdebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 It is asking for a password, I enter "android" and got the...

Perl: Multiply loops, 1 hash and regex

arrays,regex,perl,hash,perl-data-structures
I got stuck with logic behind loops (while & foreach) and AoH. I have basic knowledge about loops and arrays of hashes, but I can't quite understand how to combine them into 1 single and simple solution. My task is to check regular user's password age, if it is older...

What's going on with this hash? [duplicate]

ruby,hash
This question already has an answer here: Strange ruby behavior when using Hash default value, e.g. Hash.new([]) 4 answers I make a new hash with a default value of an empty array. h = Hash.new([]) I push a value into the hash where the key is 'a'. h['a'].push(1243) h...

Using shared hash in Perl

multithreading,perl,hash,shared
Why I get this error? Thread 1 terminated abnormally: Invalid value for shared scalar at thr_hash.pl line 8. use threads; use threads::shared; use Data::Dumper; my %h:shared; threads->create(sub{ $h{manager} = { name => 'John', surname => 'Doe', age => 27 }; })->detach; sleep 1; print Dumper \%h; ...

how can i delete a hash based on multiple values

ruby-on-rails,ruby,hash
I have the following list: hash_list = { "a"=>{"unit_id"=>"43", "dep_id"=>"153","_destroy"=>"false"}, "b"=>{"unit_id"=>"43", "dep_id"=>"153", "_destroy"=>"1"}, "c"=>{"unit_id"=>"43", "dep_id"=>"154", "_destroy"=>"false"}, "d"=>{"unit_id"=>"42", "dep_id"=>"154", "_destroy"=>"false"} } I need the result as: { "a"=>{"unit_id"=>"43", "dep_id"=>"153", "_destroy"=>"false"}, "b"=>{"unit_id"=>"43", "dep_id"=>"153", "_destroy"=>"1"}, "d"=>{"unit_id"=>"42",...

Converting hash ruby objects to positive currency

ruby-on-rails,ruby,hash,currency
I have a hash where the keys are the months and I want to convert the objects to positive numbers AND currency. INPUT hash = { 12 => -5888.969999999999, 4 => -6346.1, 3 => -6081.76, 2 => -5774.799999999999, 1 => -4454.38 } OUTPUT hash = { 12 => 5888.96, 4...

passing hash in subroutines

perl,hash,subroutine
I have made a simple perl script for printing hash key/value pairs through subroutine #!/usr/local/bin/perl #passing hash to a subroutine sub printhash{ my (%hash) = @_; foreach my $key (keys %hash){ my $value = $hash{$key}; print "$key : $value\n "; } } %hash = {'name' => 'devendra', 'age' => 21};...

Affecting a value to a multilevel hash in one instruction

perl,hash
I am looking for a more effective way to write this affect subroutine in perl: #!/usr/bin/perl use 5.010; use strict; my @keys = qw/foo bar baz/; my %hash = ( foo => {babel => 'fish'} ); affect (\%hash, 42); sub affect { my $ref = shift; $ref = $ref->{$keys[$_]} //=...

Calling an object in a search method in rails

ruby-on-rails,arrays,regex,hash
I am searching through an array of hashes and I need to find specific objects within the hash. The issue is that I am getting what I need to search from another model. Currently I am searching like this... @insur_transactions = user.transactions.find_all { |t| (t.fetch('name').downcase! =~ /user.bill.name/) } the problem...

Confusion with std::pairs initialization

c++,qt,hash,unordered-map,std-pair
The code below, when compiled produces the following errors: error C2439: 'std::pair::first' : member could not be initialized error C2440: 'initializing' : cannot convert from 'int' to 'const AnalyticsToolKit::ParcelPassingLogic::ParticipantNode &' When I comment out the bottom line however, there is no such error, so there must be something wrong with...

Client side password hash versus plain text

security,hash,passwords,client,password-hash
I'm putting together an android client (and possibly in the future iOS, web portal, etc) and php mysql server. Server side I am currently using the PHPass library to hash and salt the incoming passwords. Should I make the client send plain text passwords over HTTPS/SSL or should the client...

IDE doesn't recognize the method

c++,dictionary,hash,qt-creator,code-completion
I'm trying to acces the cityMethod() inside the class City. class City { void cityMethod() { } } So, I do: map<string,City> mymap; City c; mymap["Madrid"] = c; Now, when I do this: mymap["Madrid"].cityMethod(); Ok, it works. But the IDE(Qt) doesn't recognize the "cityMethod". Am I doing something wrong? Is...

Spark: Filtering out agregated data?

scala,hash,apache-spark,filtering
There is a table with two columns books and readers of these books, where books and readers are book and reader IDs, respectively. I need to remove from this table readers who read more then 10 books. First I group books by reader and get sizes of these groups: val...

How to remove duplicate entries from a hash based on a value

ruby-on-rails,ruby,hash
I have a list with duplicate entries . I need a list with unique entries based on unit_id. hash_list = { "a"=>{"unit_id"=>"43", "dep_id"=>"153", "_destroy"=>"false"}, "b"=>{"unit_id"=>"43", "dep_id"=>"153", "_destroy"=>"false"}, "c"=>{"unit_id"=>"43", "dep_id"=>"154", "_destroy"=>"false"}, "d"=>{"unit_id"=>"42", "dep_id"=>"154", "_destroy"=>"false"} } Expected Output: hash_list = { "a"=>{"unit_id"=>"43", "dep_id"=>"153", "_destroy"=>"false"}, "d"=>{"unit_id"=>"42",...

Cleaner way of mapping a hash in ruby

ruby,hash
Let's assume I need to do a trivial task on every element of a Hash, e.g. increment its value by 1, or change value into an array containing that value. I've been doing it like this hash.map{ |k, v| [k, v+1] }.to_h v+1 is just an example, it can be...

Deterministic hashing of Python 3 strings with adler32

python,python-3.x,hash,zlib
I read here the following: Note: To generate the same numeric value across all Python versions and platforms use adler32(data) & 0xffffffff. I am hoping to apply this to a string of the form: "S89234IX", but when I do so, I get: > zlib.adler32("S89234IX") --------------------------------------------------------------------------- TypeError Traceback (most recent call...

Efficiently checking a hashed password from database

php,mysql,hash,php-password-hash
firstly I have tried my best to find a definitive answer on this. Secondly, my code appears to work, but I want to confirm I am doing this in an efficient manner and not leaving myself open to security breaches. Firstly, I use PHP password_hash when adding user to admin...

Create hash from variables in loop

ruby-on-rails,arrays,ruby,hash
I want to end up with an array of hashes. I am starting with an array of codes: @codes = ['123', '456', '789'] I take each of those codes and hit an API with them and it returns values that I parse into variables in a loop, like so: @codes.each...

Hash holding string arrays doesn't read individual strings in Ruby on Rails

ruby-on-rails,arrays,ruby,ruby-on-rails-4,hash
I'm trying to make an array that collects individual strings from other arrays and then creates a hash that counts how many of each string is contained in estimate.bottom. Bottom belongs_to Estimate. My problem is that it doesn't currently read the individual strings, but the array as a whole. So...

Ruby hash with key as hash and value as array

ruby,hash
I am creating a hash, whose key is a hash and the value is an array. E.g., shop = Hash.new items.each do |item| grouping_key = { 'name'=> item['name'], 'value'=> item['value'] } shop [grouping_key] ||= Array.new shop [grouping_key] << item end Here, I am grouping each item based on grouping key....

How to pass a hash as optional argument to -M in command line

perl,hash,package,command-line-interface
I know that when we need to pass some arguments to the use keyword after a package name we can pass them in the command line after the -M parameter. For example: use feature 'say'; say 'hello!'; can be invoked from the command line with >perl -Mfeature=say -e"say 'hello!'" But...

Perl Variable/Regex Issue, how to use store regex matches in a loop preferably without using hashes

arrays,regex,perl,file,hash
I apologize in advance if this is confusing however this is my issue: I am trying to write a Perl script that will read data from a long config file, and allow the use to edit and overwrite a certain reocurring line in that file. However, each line that is...

C - operations on bits representing a structure

c,hash,bit-manipulation
I'm trying to write hashset in C, and I've found one hash function, that hashes according to bits in data. I have the following structure: struct triple { int a; int b; int c; }; The question is - how to get bit representation from object of type struct triple?...

Case Statement using || (OR)

ruby,hash,case
The following code I am trying to use to assign an email alias via an api to our ticketing system. @email.cc_list = case @site_id when /site1/ || /site2/; "smail-alias-1" when /site3/ || /site4/ || /site5/ || /site6/; "email-alias-2" when /site7/ || /site8/; "email-alias-3" when /site9/; "email-alias-4" when /site10/; "email-alias-5" end...

Hashing passwords even when password is server-generated?

php,mysql,security,hash
Shall I hash users of my portal when password is generated by server and user cannot change it? Logically: User can't use this passwords anywhere else as it is server-generated. Even when somebody access database illegally, they can change password and see it, but it is useless for them as...

Extracting data from log file into Perl hash

regex,perl,hash
I have a four log files. Each log file is in the same format so let's focus on one. In each log file I have to extract information such as Computer Name and such. I won't post the log file here because it has over 46,000 lines. My main goal...

Is this a bad practice for storing passwords in PHP?

php,hash,passwords,md5,salt
I'm using the crypt function in PHP to hash passwords, along with salt obviously. But I'm generating my salt by calling the md5 function over the date function. And every time the user logs in the salt gets regenerated. Is any of this bad in any way? I am still...

Order-independant Hash Algorithm

java,algorithm,hash,set
I am currently working on a collection library for my custom programming language. I already have several data types (Collection, List, Map, Set) and implementations for them (mutable and immutable), but what I was missing so far was hashCode and equals. While these are no problem for Lists as they...

How to store database records into hash ruby on rails

mysql,ruby-on-rails,hash
I'm using mysql database. Now I want to retrieve data from my database: value and time, for plotting graph. my db store up to 4000 data,and I need plot 1000 of them. First method come to my mind is: points=Hash.new Records.all.each do |record| points[record.time.to_s]=record.value.to_s end then cut the first 1000...

Creating a Hash with keys from an array and empty arrays as the values

arrays,ruby,hash
I have the array tags, which consists of a number of Strings that I need to use to create a new Hash (content) where each value is an empty array. I currently have Hash[*tags.map {|k| [k, nil]}.flatten], but this returns: { "tag1" => nil, "tag2" => nil, "tag3" => nil...

PHP password_hash() / bcrypt

php,hash,bcrypt
I am checking out the bcrypt hash-algorithm. My first test with password_hash(): echo password_hash("123", PASSWORD_BCRYPT, array( "salt" => "1234567890123456789012" )); echo password_hash("123", PASSWORD_BCRYPT, array( "salt" => "1234567890123456789012xxxxxxxxxxxxxxx" )); Both will return '$2y$10$123456789012345678901uiaLpJxTpf6VbfI5NADlsRsfvEm6aq9C'. Why the heck is the salt stored inside of the hash? This makes no sense at all for...

Convert multilevel hash in simple hash in perl

perl,hash
I have a hash that is multilevel hash i want to convert that into single level .But i am not able to do that Actual Hash: 'MainSlab' => { 'A1' => { 'Slab' => { '49_168' => { 'Amt' => '3000', 'Start' => '49', 'End' => '168' }, '169_720' =>...

SHA hash does not seem to be working correctly

java,hash,cryptography
I am trying to build a simple password authenticator where passwords that have been hashed using SHA-256 . I found a couple calculators online (http://onlinemd5.com/) that hashed "password" to "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8" I tried a couple other passwords with expected results. So I tried to implement a fairly straight forward set of...

Why k and l for LSH used for approximate nearest neighbours?

algorithm,hash,knn,locality-sensitive-hash,approximate-nn-searching
In all the Locality Sensitive Hashing explanations (i.e. http://en.wikipedia.org/wiki/Locality-sensitive_hashing#LSH_algorithm_for_nearest_neighbor_search ) They describe that k Hash Functions are generated, but only l (l < k) are used in the hash tables to hash the values. Why generating k at all and not just generate l? Why the seperate factors k and...

How does Python mimic the behavior of Perl multi-level hash chain extraction and concatenation

python,perl,dictionary,hash
I've always use Perl hash reference tricks to deal with tree structures. This time, I have to do it in Python that I am not really familiar with. For example, in the following code. I create a hash chain and cut it to half. Then I concatenate one piece to...

Difficulties initializing an array in Perl

arrays,perl,hash
I have the following code: print Dumper($dec_res->{repositories}[0]); print Dumper($dec_res->{repositories}[1]); my @repos = ($dec_res->{repositories}); print scalar @repos . "\n"; and the output is the following: $VAR1 = { 'status' => 'OK', 'name' => 'apir', 'svnUrl' => 'https://url.whatever/svn/apir', 'id' => 39, 'viewvcUrl' => 'https://url.whatever/viewvc/apir/' }; $VAR1 = { 'status' => 'OK', 'name'...

Merge two arrays of hashes based on comparison of multiple keys

arrays,ruby,hash
I have two arrays of hashes: a1 = [{ ID: 12496, name: "Robert", email: "[email protected]" }, ...] a2 = [{ ID: 12496, name: "Robert", ORDER_NO: 5511426 }, ...] I would like to find the hashes in a2 whose ID and name fields match the ID and name fields of an...

'floor' value of hash?

ruby,hash
I have a hash with a default value of 0: Hash.new(0) Assuming an integer value, is there a way to set a 'floor', such that if the value goes below the floor, that floor is returned? example: h = Hash.new(0) h.floor = 0 h[:five] += 5 h[:five] #=> 5 h[:negative_five]...

Generating an MD5 Hash with a char[]

java,security,hash,md5,message-digest
How would one go about converting a char[] password obtained using this method: char[] password = passwordInputField.getPassword(); To an MD5 Hash? Normally I would use the method below, but getBytes is only compatible with Strings: MessageDigest md = MessageDigest.getInstance("MD5"); md.update(password.getBytes()); String hashedPass = new BigInteger(1, md.digest()).toString(16); ...

Iterating through a array of hashes in a hash that has multiple indexes

arrays,perl,loops,hash,hashmap
I am currently writing a perl script that has a few hashes that containing: (Do not take this as lines of codes, it's just to show/explain) $details{tester_name} is "UFLEX-06" $details{op_sys} is "Windows" $details{igxl_vn} is "8.00.01_uflx (P7)" $details{slot} -> see below for details $details{board_name} -> see below for details Now in...

Disable hash randomization from within python program

python,python-3.x,hash
Starting with Python 3.3, the hashing algorithm is non-deterministically salted to avoid a certain kind of attack. This is nice for webservers but it's a pain when trying to debug a program: Every time I run my script, dict contents are iterated in a different order. Some earlier versions of...

Path reconstruction with Hashing?

java,algorithm,hash
I've been trying to figure out how to find a O(n) time complexity algorithm to solve the following in Java: We are given an input pair with a start point and end point, and we have to construct a path such that the start of one input matches the end...

Nested Loop in Ruby, Hash and Array

javascript,arrays,ruby,object,hash
How can i do this in Ruby var pCodePrice = { 'GR1': 3.11, 'SR1': 5, 'CF1': 11.23 }; var basket = ['GR1', 'SR1', 'GR1', 'GR1', 'CF1']; var total = []; for (i = 0, x = basket.length; i < x; i++) { for (var prop in pCodePrice) { if (basket[i]...

Facebook android app error : Invalid key hash

android,hash,facebook-sdk-4.0
I have imported the Facebook SDK to my android project, first time I logged in to Facebook from my android application it worked, but the second time I got this error : Invalid key hash. The key hash "..." does not match any stored key hashes. Configure your app key...

How to read data from a different file without using YAML or JSON

ruby,hash
I'm experimenting with a Ruby script that will add data to a Neo4j database using REST API. (Here's the tutorial with all the code if interested.) The script works if I include the hash data structure in the initialize method but I would like to move the data into a...

Unique hash/index for time interval

database,mongodb,database-design,hash
I am working on a simple resource booking app. The use of the resource is exclusive so it can't be booked more than once at the same time. I am wondering if this constraint can be enforced by a unique index instead of having to build validation in code. The...

How do I force iron-router to react when the hash has not apparently changed?

hash,meteor,iron-router
When using iron-router to scroll to a hash using an anchor button referencing the id of the next section, such as this: <a class="button" href="{{pathFor 'home' hash='about'}}"> iron-router happily takes us to the about section the first time the button is clicked. if you scroll back up using the mouse...