Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epoch hashing #49

Closed
ssorenso opened this issue Oct 2, 2018 · 1 comment
Closed

Epoch hashing #49

ssorenso opened this issue Oct 2, 2018 · 1 comment

Comments

@ssorenso
Copy link

ssorenso commented Oct 2, 2018

Hi Team,

I don't know whether or not you think this is a valid bug or not.

If I do something like:

// HashMaker performs a salted hash based upon epoch
func HashMaker() string {
	now := time.Now()
	hash := hashids.NewData()
	value := now.Unix()
	hash.Salt = "hello world"
	h, _ := hashids.NewWithData(hash)
	e, _ := h.Encode(toIntSlice(string(value)))
	got, _ := h.DecodeWithError(e)
	fmt.Println("should be", value, "got", got)

	return e
}

I get something like:

should be 1538515448 got [65533]
jolM
should be 1538515449 got [65533]
jolM
should be 1538515450 got [65533]
jolM
should be 1538515451 got [65533]
jolM

I guess that my expectation is to see something like:

should be <epoch> got <epoch>
<hash>

I am sending the epoch as a string into the hash as data, and I can replace it for the salt as well, and it results in the same problem.

@speps
Copy link
Owner

speps commented Oct 22, 2018

It would be good to see your toIntSlice method, as I think you should be able to encode the epoch directly instead of having to make it into multiple numbers using EncodeInt64. I added a new test in 6ba254b that shows how to do it.

@speps speps closed this as completed Oct 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants