For an app I build, I want to use the ID generated by Firebase push as an email address local part. Since the dash
(-) is not allowed as first character, I would like to replace it with another character.
This has to be reversible though. Therefore I want to know, which characters does the Firebase push ID consist of? So far I have seen:
Sample: -KD3rcGMuucRDjKOTK3O
A unique device identifier (UDID) is a 40-character string assigned to certain Apple devices including the iPhone, iPad and iPod Touch.
If you're not familiar with Firebase's push IDs, they are the chronological, 20-character unique IDs generated when you write lists of data to Firebase from any of our client libraries.
Firebase users have a fixed set of basic properties—a unique ID, a primary email address, a name and a photo URL—stored in the project's user database, that can be updated by the user (iOS, Android, web).
The Push Method The push() method will create a unique id when the data is pushed.
There are probably a lot of better ways to generate a unique email address than by using Firebase's push ids and then mangling them. That said, if you want to learn more about how Firebase generates its push ids, read this blog post: The 2^120 Ways to Ensure Unique Identifiers. It also explains why you should not rely on push ids to be unguessable/secure.
An important thing to realize from that post is that the first 8 characters of a push id contain an encoded timestamp, which is also the reason they always start with the same characters if you generate them close to each other.
The post also contains a link to a gist of the JavaScript code to generate a push id.
The set of characters that Firebase selects from is:
-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz;
As you can see the -
is just the first character in this dictionary, which is the only reason the push ids (currently) all start with a -
. At some point in the future they will start with a 0
, then a 1
, etc. If you take the code in the gist, you could calculate when each of those roll-overs happen.
Finally: I once wrote an answer on how to get the timestamp back from a push id. Doing so is not recommended, but it can be a fun experiment: Can you get the timestamp from a Firebase realtime database key?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With