All Projects → emvi → hide

emvi / hide

Licence: MIT License
ID type with marshalling to/from hash to prevent sending IDs to clients.

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to hide

urbit-visor
Urbit Visor is an extension which transforms your web browser into a first class Urbit client.
Stars: ✭ 65 (+44.44%)
Mutual labels:  id
goimpulse
高可用,高性能的分布式发号服务
Stars: ✭ 17 (-62.22%)
Mutual labels:  id
platform device id
flutter plugin to get device id
Stars: ✭ 32 (-28.89%)
Mutual labels:  id
mongoose-auto-increment-reworked
An auto-incrementing field generator for Mongoose 4 & 5
Stars: ✭ 17 (-62.22%)
Mutual labels:  id
DocumentReader-iOS
iOS Framework for reading and validation of identification documents
Stars: ✭ 54 (+20%)
Mutual labels:  id
rig
RIG - A Randomised ID Card Generator
Stars: ✭ 20 (-55.56%)
Mutual labels:  id
leafserver
🍃A high performance distributed unique ID generation system
Stars: ✭ 31 (-31.11%)
Mutual labels:  id
vue-uniq-ids
Vue.js 2.x plugin that helps to use id-related attributes with no side-effect
Stars: ✭ 32 (-28.89%)
Mutual labels:  id
hashids.sql
PL/pgSQL implementation of hashids library
Stars: ✭ 40 (-11.11%)
Mutual labels:  id
firebase-id-tokens-verifier
Code snippet to show how to verify Firebase ID tokens using Ruby
Stars: ✭ 32 (-28.89%)
Mutual labels:  id
cedula-panama
Validador javascript de la cédula de panama. A javascript validator of the Panamenian id (cedula)
Stars: ✭ 26 (-42.22%)
Mutual labels:  id
verify-apple-id-token
Verify the Apple id token on the server side.
Stars: ✭ 49 (+8.89%)
Mutual labels:  id
gid
Golang 分布式ID生成系统,高性能、高可用、易扩展的id生成服务
Stars: ✭ 55 (+22.22%)
Mutual labels:  id
sid
Generate Sortable Identifiers
Stars: ✭ 26 (-42.22%)
Mutual labels:  id
distributed-id
基于netty4+twitter-snowFlake分布式Id生成之服务实现
Stars: ✭ 18 (-60%)
Mutual labels:  id
tsid-creator
A Java library for generating Time Sortable Identifiers (TSID).
Stars: ✭ 16 (-64.44%)
Mutual labels:  id
sandid
Every grain of sand on Earth has its own ID.
Stars: ✭ 39 (-13.33%)
Mutual labels:  id
ids
高效的分布式id生成器,每个客户端实例tps可达到100万,服务端毫无压力。即使服务端宕机了,id生成依然可用。支持多数据中心,支持id加密。
Stars: ✭ 47 (+4.44%)
Mutual labels:  id
id-mask
IDMask is a Java library for masking internal ids (e.g. from your DB) when they need to be published to hide their actual value and to prevent forging. It has support optional randomisation has a wide support for various Java types including long, UUID and BigInteger. This library bases its security on strong cryptographic primitives.
Stars: ✭ 39 (-13.33%)
Mutual labels:  id
shortid
Super short, fully unique, non-sequential and URL-friendly Ids
Stars: ✭ 20 (-55.56%)
Mutual labels:  id

Hide IDs

Go Reference Go Report Card Chat on Discord

Hide is a simple package to provide an ID type that is marshaled to/from a hash string. This prevents sending technical IDs to clients and converts them on the API layer. Hide uses hashids as its default hash function. But you can provide your own by implementing the Hash interface and configuring it using hide.UseHash.

Read our full article on Medium.

Installation

go get github.com/emvi/hide/v2

Example

Consider the following struct:

type User struct {
    Id       int64  `json:"id"`
    Username string `json:"username"`
}

When marshaling this struct to JSON, the ID will be represented by a number:

{
    "id": 123,
    "username": "foobar"
}

In this case, you expose the technical user ID to your clients. By changing the type of the ID, you get a better result:

type User struct {
    Id       hide.ID `json:"id"`
    Username string  `json:"username"`
}

Notice that the int64 ID got replaced by the hide.ID, which internally is represented as an int64 as well, but implements the marshal interface. This allows you to cast between them and use hide.ID as a replacement. The resulting JSON changes to the following:

{
  "id": "beJarVNaQM",
  "username": "foobar"
}

If you send the new ID (which is a string now) back to the server and unmarshal it into the hide.ID type, you'll get the original technical ID back. It's also worth mentioning that a value of 0 is translated to null when an ID is marshaled to JSON or stored in a database.

View the full demo

Contribute

See CONTRIBUTING.md

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].