Make it possible to create an account with an already encrypted password.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@1390 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2004-01-31 06:24:01 +00:00
parent e704a51391
commit d16b0c0a3d
2 changed files with 56 additions and 3 deletions
@@ -0,0 +1,40 @@
//
// $Id: Password.java,v 1.1 2004/01/31 06:24:01 mdb Exp $
package com.samskivert.servlet.user;
/**
* Represents an encrypted password. Currently only used when creating
* user accounts.
*/
public class Password
{
/**
* Creates a password from the supplied username and (unencrypted)
* password.
*/
public Password (String username, String password)
{
_encrypted = UserUtil.encryptPassword(username, password);
}
/**
* Creates a password directly from the encrypted text. This text
* <em>must</em> have been created using {@link
* UserUtil#encryptPassword} or via the same algorithm.
*/
public Password (String encrypted)
{
_encrypted = encrypted;
}
/**
* Returns the encrypted password text.
*/
public String getEncrypted ()
{
return _encrypted;
}
protected String _encrypted;
}
@@ -1,5 +1,5 @@
//
// $Id: UserRepository.java,v 1.37 2003/12/15 23:12:47 mdb Exp $
// $Id: UserRepository.java,v 1.38 2004/01/31 06:24:01 mdb Exp $
//
// samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne
@@ -116,6 +116,19 @@ public class UserRepository extends JORARepository
String email, int siteId)
throws InvalidUsernameException, UserExistsException,
PersistenceException
{
return createUser(username, new Password(username, password),
realname, email, siteId);
}
/**
* Like {@link #createUser(String,String,String,String,int)} except
* that the supplied password has already been encrypted.
*/
public int createUser (String username, Password password, String realname,
String email, int siteId)
throws InvalidUsernameException, UserExistsException,
PersistenceException
{
// create a new user object...
User user = new User();
@@ -130,7 +143,7 @@ public class UserRepository extends JORARepository
* in preparation for inserting the record into the database for the
* first time.
*/
protected void populateUser (User user, String username, String password,
protected void populateUser (User user, String username, Password password,
String realname, String email, int siteId)
throws InvalidUsernameException
{
@@ -146,7 +159,7 @@ public class UserRepository extends JORARepository
}
user.username = username;
user.password = UserUtil.encryptPassword(username, password, true);
user.password = password.getEncrypted();
user.realname = realname;
user.email = email;
user.created = new Date(System.currentTimeMillis());