-
-
Save xkef/73b8763e80bd0b67f3f01e1bc2842696 to your computer and use it in GitHub Desktop.
url shorteners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# say we have a service shrtnr.io, | |
# this bcrypt implementation (10 salting rounds) | |
# gives a unique hash for the short url | |
# -> shrtnr.io/abcd (abcd - postfix must be choosen with constraints by user) | |
$ htpasswd -nbBC 10 abcd 'www.google.com' | |
# out: abcd:$2y$10$SkjTJYoRgELA7E1dZe11KOB4cT0DsYxbqZGIBJTwZSHbbx.TPnAZq | |
# bcrypt hash of www.google.com for short '/abcd' | |
$ echo "$(htpasswd -nbBC 10 abcd 'www.google.com' | sed 's/.*\://g')" | urlenc --enc # urlenc --version -> v1.1 (1386011) | |
# out: %242y%2410%24%2F.ptThgwxETajDl0vxIHKuyZ0M4MCo.QySqajA9H4v8t7SQXLzJvm | |
# we would have in our key-value store: | |
# { "$2y$10$SkjTJYoRgELA7E1dZe11KOB4cT0DsYxbqZGIBJTwZSHbbx.TPnAZq": "abcd" } | |
# ---- | |
# to give the user rights for deletetion this is easily extensible, | |
# he just gets a random hash of this which can be verified | |
$ htpasswd -nbBC 10 "$2y$10$SkjTJYoRgELA7E1dZe11KOB4cT0DsYxbqZGIBJTwZSHbbx.TPnAZq - abcd" "good (internal password) password" | |
# deletetion secret: "y.TPnAZq:$2y$10$HGFa/jlSArcjPUBCyz05e.GnOx8.U4QEbb7CUeukUDjYUZEtlow1m" | |
# --- | |
# To make this scale better and approach the url compression problem, | |
# I would look at AVL Tree data structures. | |
# To not always go to your store, use caching - bcrypt is expensive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment