Mar 31, 2018 HERE IN THIS SQL Tutorial WE WILL GENERATE UNIQUE ID(CHARACTER + NUMBER) FOR CUSTOMER IN SQL SERVER HERE WE REQUIRED SQL SERVER MANAGEMENT STUDIO USING CAST,RIGHT,PERSISTED FUNCTIONALITY TABLE AND. Oct 31, 2019 First, you create an Azure Cosmos DB SQL API account using the Azure portal, then create a Java app using the SQL Java SDK, and then add resources to your Cosmos DB account by using the Java application. Azure Cosmos DB is a multi-model database service that lets you quickly create and query document, table, key-value, and graph databases with global distribution and horizontal scale.
A unique primary key allows child records in other tables to point uniquely to the parent record in the target table. A random key within a range provides an efficient way to access the database when the table is clustered based on the primary key. You can use a Java transformation to generate unique and random numeric keys within a specific range. Jun 10, 2006 At the first glance it seems to be satisfied Unique key as its using current time and hashing to generate key but GetHashCode doesn’t procduce unique code everytime. Althought Microsoft is using Double Hashing algorithms with N Number of collision resolving double hash function but during my experimentation I found lot of collisions. Unique Key in SQL. A unique key is a set of one or more than one fields/columns of a table that uniquely identify a record in a database table. You can say that it is little like primary key but it can accept only one null value and it cannot have duplicate values. To generate secrete key we can use Java KeyGenerator class which provides the functionality of a secret (symmetric) key generator. Key generators are constructed using one of the getInstance class methods of this class. GetInstance method of KeyGenerator takes parameter name of algorithm.
UUID / GUID (Universally / Globally Unique Identifier) is frequently use in programming. Some of its usage are for creating random file names, session id in web application, transaction id and for record’s primary keys in database replacing the sequence or auto generated number.
To generate UUID in Java we can use the
java.util.UUID
class. This class was introduced in JDK 1.5. The UUID.randomUUID()
method return a UUID object. To obtain the value of the random string generated we need to call the UUID.toString()
method.We can also get the version and the variant of the UUID using the
version()
method and variant()
method respectively. Let’s see the code snippet below:The result of our program is:
- How do I backup MySQL databases in Ubuntu? - December 16, 2019
- How do I set the time of java.util.Date instance to 00:00:00? - October 24, 2019
- How to Install Consolas Font in Mac OS X? - March 29, 2019
Ranch Hand
posted 10 years agoGuys,
I need to generate a unique hash key for all users that are registering on my application and send them a confirmation email link that will activate their account. I'm considering to use UUID for generating the unique id. I'm trying to generate it based on the users email address. I would like to know if that would be a correct approach??
I'm trying something like:
I would like to know if this is this solid, secure enough or do I have to do more and use a Crypto kind of an implementation to acheive this??
I need to generate a unique hash key for all users that are registering on my application and send them a confirmation email link that will activate their account. I'm considering to use UUID for generating the unique id. I'm trying to generate it based on the users email address. I would like to know if that would be a correct approach??
I'm trying something like:
I would like to know if this is this solid, secure enough or do I have to do more and use a Crypto kind of an implementation to acheive this??
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Did a rm -R / to find out that I lost my entire Linux installation!
Ranch Hand
posted 10 years agoI would like to know which one is better??
MD5
SHA1
UUID
MD5
SHA1
UUID
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Did a rm -R / to find out that I lost my entire Linux installation!
Java Cowboy
posted 10 years agoThere is a contradiction in the term 'unique hash key'. Hash codes are not unique - a hashing algorithm will always have multiple possible inputs that result in the same hash code. (It's very easy to see theoretically why this is so - the hash code has fewer bits than the original data, so if there is a mapping from original data to hash keys, there must be some overlap). It's not possible to create unique IDs with a hashing algorithm. MD5 and SHA1 are hashing algorithms, so they do not guarantee that you get a unique output for any input.
UUID is a universally unique identifier. It is not a hashing algorithm.
Jothi Shankar Kumar wrote:
This will not work and will most likely give you an IllegalArgumentException. You cannot put any arbitrary string into this method - it has to be a string that represents an UUID (as returned by UUID.toString()). It's not a method that generates a unique ID based on arbitrary input.
If you're looking for something that creates a unique ID based on arbitrary input - such a method can't exist in principle. (If you invent a method that does this, then you have discovered the ultimate compression algorithm and you'll win a Nobel prize in information theory... See Jan Sloot).
Ranch Hand
posted 10 years agoSo how could I acheive a unique key for my case here?
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Did a rm -R / to find out that I lost my entire Linux installation!
Java Cowboy
posted 10 years agoGenerate a unique ID, then store in a database somewhere which ID is associated with which user. When the user tries to activate the account using the ID, look the user's information up in the database.
You can create random unique IDs using the UUID class:
But, as I explained above, you cannot create unique identifiers based on some arbitrary input such as the user's e-mail address.
You can create random unique IDs using the UUID class:
But, as I explained above, you cannot create unique identifiers based on some arbitrary input such as the user's e-mail address.
author
posted 10 years agoJothi Shankar Kumar wrote:So how could I acheive a unique key for my case here?
Hash and unique key are two different things, but to answer your question...
If you want to generate a key for a single application, then the UUID class should be fine. If it is a group of applications, meaning that you can be generating it from many applications and on many machines -- then you probably need to create your own class that uses the host, pid, and probably system time. Regardless, it is probably best to use a service (such as a database) to generate the id.
Henry
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ranch Hand
posted 10 years agoJesper Young wrote:Generate a unique ID, then store in a database somewhere which ID is associated with which user. When the user tries to activate the account using the ID, look the user's information up in the database.
You can create random unique IDs using the UUID class:
But, as I explained above, you cannot create unique identifiers based on some arbitrary input such as the user's e-mail address.
You can create random unique IDs using the UUID class:
But, as I explained above, you cannot create unique identifiers based on some arbitrary input such as the user's e-mail address.
I understand what you meant here. But how unique is the randomUUID() generator?
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Did a rm -R / to find out that I lost my entire Linux installation!
Java Cowboy
posted 10 years agoThe API documentation of class java.util.UUID explains that this method generates a type 4 (or version 4) UUID. The exact details of the algorithm are explained in RFC 4122.
For practical purposes, you don't need to worry that the generated IDs could be non-unique.
For practical purposes, you don't need to worry that the generated IDs could be non-unique.
Ranch Hand
posted 10 years agoSomewhat convincing answer here... http://en.wikipedia.org/wiki/Universally_Unique_Identifier#Java
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Did a rm -R / to find out that I lost my entire Linux installation!
Rancher
posted 10 years agoJothi:
I'm not sure what you mean by 'somewhat convincing'. I went to the page, and it's not an argument, but an explanation.
John.
I'm not sure what you mean by 'somewhat convincing'. I went to the page, and it's not an argument, but an explanation.
John.
Ranch Hand
posted 10 years ago
It was convincing to me that the unique key that I'd be generating will not be a duplicate!
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Did a rm -R / to find out that I lost my entire Linux installation!
Ranch Hand
posted 10 years agoJothi Shankar Kumar wrote:I need to generate a unique hash key for all users that are registering on my application and send them a confirmation email link that will activate their account. I'm considering to use UUID for generating the unique id. I'm trying to generate it based on the users email address. I would like to know if that would be a correct approach??
No it's not. The best way is to keep a global counter (starting at 0). When a user registers he/she gets the counter number as id, and then you increment the counter by 1.
In this way you're 100% sure each user gets a unique id. There is not other way to ensure that really.
Also, from a principle standpoint, the id's will be random. They're random in the sense that no user can know what number they're going to get.
Generate Guid In Java
Sheriff
posted 10 years agoUlrika Tingle wrote:
Jothi Shankar Kumar wrote:I need to generate a unique hash key for all users that are registering on my application and send them a confirmation email link that will activate their account. I'm considering to use UUID for generating the unique id. I'm trying to generate it based on the users email address. I would like to know if that would be a correct approach??
No it's not. The best way is to keep a global counter (starting at 0). When a user registers he/she gets the counter number as id, and then you increment the counter by 1.
In this way you're 100% sure each user gets a unique id. There is not other way to ensure that really.
But you have to synchronize the counter, or you will run into problems in a multi-threaded environment. AtomicLong can help out here to do the hard work, with its incrementAndGet() and getAndIncrement() methods, the synchronized versions of ++l and l++.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask QuestionsHow To Answer Questions
How To Ask QuestionsHow To Answer Questions
Ranch Hand
posted 10 years agoGuys, this seems to be running totally off the topic. I'm looking for a solution to send the user an email which has a registration key and it is this registration key that I have to generate uniquely for each user.
Why will I create a counter starting at 0 and increment that for each user when I store the user details in the database. Ofcourse I have the primary key. Don't I?
Why will I create a counter starting at 0 and increment that for each user when I store the user details in the database. Ofcourse I have the primary key. Don't I?
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Did a rm -R / to find out that I lost my entire Linux installation!
Java Generate Keystore
Rancher
posted 10 years agoJava Code To Generate Unique Key West
a suitably large random string would work then. store the string in the DB, compare when they return.
It doesn't need to be unique if they send their email address too.
It doesn't need to be unique if they send their email address too.