DELIMITER //
CREATE FUNCTION django_password(
  pass VARCHAR(32)
) RETURNS VARCHAR(128) 
DETERMINISTIC
BEGIN
	DECLARE salt char(5);
	DECLARE hash VARCHAR(40);
	SET salt = MID(RAND(), 3, 5);
	SET hash = SHA(CONCAT(salt, pass));
	RETURN CONCAT('sha1$', salt, '$', hash);
END//
