Firebase Dashboard rounding Integer to even number [duplicate] - firebase

This question already has an answer here:
Storing 'long' type in firebase
(1 answer)
Closed 5 years ago.
Adding a big number in Firebase Dashboard is always rounding it to an even number.
For example adding this 10156050407559741, it changes to 10156050407559740 or 10154224540777163 to 10154224540777164.

Basing from #MichaelLehenbauer's answer here:
Integers between 2^52 and 2^64 may lose precision (get rounded to the nearest integer representable by a 64-bit float).
And from the options on the same post, it would be best to store the numbers as Strings instead (still depending on your use-case though):
Store the numbers as strings. As you suggested, you can just store the number as a string. But this can be inconvenient and does limit the validation you can do in the security rules.

Related

What is the max numeric value that can be stored on firebase?

I'm building a system that will eventually store extremely large number values (double or floating point types, not int) and I'm using firestore to store my data. Is there a cap for how big numbers can grow in a firestore database? I can't seem to find any documentation anywhere.
As per the documentation, Firestore allows only 64 bit signed integers. A 64-bit signed integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive).
Same for float: Firestore allows 64-bit double precision, IEEE 754
I just tried adding a random number over that limit and you get.
Then I tried requesting the document and that's the data you get:
It'll be hard to get the precise value if you store it as a number. You may be interested storing the number in string format if that numbers are that large. But do keep the 1 MiB (1,048,576 bytes) limit of a document in mind.

Maximum Size for a phone number extension? [duplicate]

This question already has answers here:
What's the longest possible worldwide phone number I should consider in SQL varchar(length) for phone
(6 answers)
Closed 10 months ago.
Im trying to make a phone number extension field but Im not sure what the maximum amount of digits it can have and I dont see any sources online.
I was asking the same question myself but I couldn't find anything conclusive. I did, however, find a couple of useful bits of information that helped me come to a decision.
Robert Pepper at GetVoIP, says:
In an older PBX, that would be four digits, and limited to the same building. In a hosted PBX, it can be three, four or five digits, and the extension can be anywhere in the world, including your cell phone.
But, GoToConnect's website states:
An extension is a three to six-digit number identifying a specific call path configuration that allows you to dial and connect to another caller internally.
With that in mind, I decided to use six digits as a max length, until I learn otherwise.
Generally E.164 formatting using on apps.On this format max length is 15 this but using '+' for countrycode.
if you use Instead of '+' '00' it will be max 16 .

storing as integer vs string size

I have checked the Docs but I got confused a bit. When storing a long integer such as 265628143862153200. Would it be more efficient to store it as a string of integer.
This is what I need help with is the below calculation corrent?
Integer:
length of 265628143862153200 *8 ?
String:
length of 265628143862153200 +1 ?
The Firebase console is not meant to be part of administrative workflows. It's just for discovery and development. If you have production-grade procedures to follow, you should only write code for that using the provided SDKs. Typically, developers make their own admin sites to deal with data in Firesotre.
Also, you should know that JavaScript integers are not "big" enough to store data to the full size provided by Firestore. If you want to use the full size of a number field, you will have to use a system that supports Firestore's full 64 bit signed integer type.
If you must store numbers bigger than either limit, and be able to modify them by hand, consider instead storing multiple numbers, similar to the way Firestore's timestamp stores seconds and nanoseconds as separate numbers, so that the full value can overflow greater than signed 64 bits.

How many bits of integer data can be stored in a DynamoDB attribute of type Number?

DynamoDB's Number type supports 38 digits of decimal precision. This is not big enough to store a 128-bit integer which would require 39 digits. The max value is 340,282,366,920,938,463,463,374,607,431,768,211,455 for unsigned 128-bit ints or 170,141,183,460,469,231,731,687,303,715,884,105,727 for signed 128-bit ints. These are both 39-digit numbers.
If I can't store 128 bits, then how many bits of integer data can I store in a Number?
DynamoDB attribute of type Number can store 126-bit integers (or 127-bit unsigned integers, with serious caveats).
According to Amazon's documentation:
Numbers can have up to 38 digits precision. Exceeding this results in an exception.
This means (verified by testing in the AWS console) that the largest positive integer and smallest negative integers, respectively, that DynamoDB can store in a Number attribute are:
99,999,999,999,999,999,999,999,999,999,999,999,999 (aka 10^38-1)
-99,999,999,999,999,999,999,999,999,999,999,999,999 (aka -10^38+1)
These numbers require 126 bits of storage, using this formula:
bits = floor (ln(number) / ln (2))
= floor (87.498 / 0.693)
= floor (126.259)
= 126
So you can safely store a 126-bit signed int in a DynamoDB.
If you want to live dangerously, you can store a 127-bit unsigned int too, but there are some caveats:
You'd need to avoid (or at least be very careful) using such a number as a sort key, because values with a most-significant-bit of 1 will sort as negative numbers.
Your app will need to convert unsigned ints to signed ints when storing them or querying for them in DynamoDB, and will also need to convert them back to unsigned after reading data from DynamoDB.
If it were me, I wouldn't take these risks for one extra bit without a very, very good reason.
One logical question is whether 126 (or 127 given the caveats above) is good enough to store a UUID. The answer is: it depends. If you are in control of the UUID generation, then you can always shave a bit or two from the UUID and store it. If you shave from the 4 "version" bits (see format here) then you may not be losing any entropy at all if you are always generating UUIDs with the same version.
However, if someone else is generating those UUIDs AND is expecting lossless storage, then you may not be able to use a Number to store the UUID. But you may be able to store it if you restrict clients to a whitelist of 4-8 UUID versions. The largest version now is 5 out of a 0-15 range, and some of the older versions are discouraged for privacy reasons, so this limitation may be reasonable depending on your clients and whether they adhere to the version bits as defined in RFC 4122.
BTW, I was surprised that this bit-limit question wasn't already online... at least not in an easily-Google-able place. So contributing this Q&A pair so future searchers can find it.

Why the salt is 8 characters long? [duplicate]

This question already has answers here:
What is the optimal length for user password salt? [closed]
(5 answers)
Closed 4 years ago.
Why is the salt not more than 8 ~ 16 characters long?
Also, why in most cases is it in the front or end of the password, and not in different positions?
Is this to make it harder for the breaker? Or is it useless?
Because more salt doesn't serve a useful purpose.
The point of salt is to prevent some parallel attacks from working in a reasonable amount of time/memory, and/or drive space. (You can no longer have a table that says Hash A => Password A, because even if you had enough disk space to construct a rainbow table, the salt makes the number of possible entries way beyond feasibility. And you can no longer hash a potential password once and compare it against a bunch of hashes at a time, because the salt is quite likely to be different for each hash.)
16 characters gives you somewhere between 10^16 and 96^16 times as many possibilities, which already fits the definition of "way beyond feasibility". Past a certain point, you're simply increasing your own storage requirements for no significant benefit.
The salt of 8 characters is enough against any imaginable in real life dictionary attack, it makes any dictionary or rainbow table useless.

Resources