0

I have a function which takes 2 strings, say userName and password as parameters. I need to generate a random user id with these 2 strings as input. Can anyone suggest a solution ?

generateUserId(String userName, String password)

Thanks

7
  • 1
    do you mean a cryptographic strong hash or is it just some randomized text? Commented Jun 1, 2012 at 9:35
  • yes it depends on the purpose of the id Commented Jun 1, 2012 at 9:38
  • The name of your function might reveal a problem: if you intend to identify users by this string, you might have a problem when a user wants to change his password... Either it is badly named or you have a serious design problem. Commented Jun 1, 2012 at 9:38
  • I am new to Java. What i got while searching is the usage of Math.random() . But this doesnot have any dependency with the input strings. Commented Jun 1, 2012 at 9:39
  • what exactly are you trying to accomplish with the user id? wouldn't it make more sense to use an autoincrement with the column of the id? Commented Jun 1, 2012 at 9:41

2 Answers 2

2

This might help: http://docs.oracle.com/javase/1.5.0/docs/api/java/util/UUID.html Fiddle around with it.

String res = UUID.nameUUIDFromBytes((password+username).getBytes()).toString();
System.out.println(res);
Sign up to request clarification or add additional context in comments.

Comments

1

how about something like this

int seed = userName.hashCode() & password.hashCode(); 
return new String(new Random(seed).nextLong());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.