Received: by 10.181.11.234 with SMTP id el10mr139258wid.2.1347988201109; Tue, 18 Sep 2012 10:10:01 -0700 (PDT) Received: by 10.236.192.168 with SMTP id i28mr171072yhn.7.1347988200948; Tue, 18 Sep 2012 10:10:00 -0700 (PDT) Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!hq-usenetpeers.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!lightspeed.eweka.nl!209.85.212.215.MISMATCH!7no20804147wig.0!news-out.google.com!ed8ni114471314wib.0!nntp.google.com!v8no90445qap.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Tue, 18 Sep 2012 10:10:00 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.214; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T NNTP-Posting-Host: 173.164.137.214 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: get hexadecimal hash string for a number From: Lew Injection-Date: Tue, 18 Sep 2012 17:10:00 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.java.programmer:18823 Magnus Warker wrote: > I want users to register on a site and send confirmation emails to them. > These emails should contain a link like this: > > http://myurl?registration=E4AC4BD4 > > Here, "E4AC4BD4" should be a unique string. My idea for such a string is > just to hash an integer, i. e. the internal database key for the > registration record. > > However, I actually don't know how to get such a hash. I tried BCrypt, > but this produces hashes built out of characters that I would not want > to be in a URL, e. g. commatas and that. > > I would like to have a string like this: > > - hexadecimal only > - fixed size, e. g. always n characters, independend of the integer > > Can you help? First of all, hashing a unique integer is silly. It's already unique! If you have a reliably unique, stable integer ID, you don't need to hash it! Just use the value. Got that? Good, because an internal database ID is not reliable. It's *internal*! It's not meant to be used externally! Got that? Good, because the database record has (or you're not doing it right) an external unique key, one based on visible attributes. You could hash that key. Or you could perhaps use http://docs.oracle.com/javase/7/docs/api/java/rmi/server/UID.html You'll want to store that UID with the registration record. First and foremost google around for hash codes and how to use them. Your lack of understanding will screw you otherwise. -- Lew