[opencms-dev] Has anyone created a Web User self registration JSP???
Marc Fiévet
marc at fievet.be
Wed Feb 7 21:06:09 CET 2007
Hello, try this:
<%@ page session="false" %>
> <%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
>
> <%@ page import="org.opencms.jsp.CmsJspActionElement,
> org.opencms.file.CmsObject,
> org.opencms.file.CmsUser,
> java.sql.*,
> java.io.*,
> java.util.Hashtable"
> %>
> <%
> String firstName = request.getParameter("fname");
> String lastName = request.getParameter("lname");
> String userName = request.getParameter("uname");
> String email = request.getParameter("email");
> String password1 = request.getParameter("pw1");
> String password2 = request.getParameter("pw2");
> String group = "Guests";
> CmsJspActionElement cmsjsp =
> new CmsJspActionElement( pageContext, request, response );
>
> CmsObject cms = cmsjsp.getCmsObject();
>
> // simple validation
> if ( userName == null || "".equals(userName) ) {
> throw new Exception( "User Name is required." );
> } else if ( email == null || "".equals(email) ) {
> throw new Exception( "Email is required." );
> } else if ( password1 == null || "".equals( password1 ) ) { throw new
> Exception( "Password is required." ); } else if ( password2 == null ||
> "".equals( password2 ) ) { throw new Exception( "Password Again is
> required." ); } else if ( email == null || "".equals( email ) ) {
> throw new Exception( "Email address must be valid." ); } else if (
> !password1.equals( password2 )) { throw new Exception( "Passwords do
> not match." ); } else if ( password1.length() < 7 ) { throw new
> Exception( "Password must be at least 7 characters." ); } // Set
> default values for optional params. if ( firstName == null ) {
> firstName = ""; }
>
>
>
> group = "Guests";
>
>
> if ( lastName == null ) {
> lastName = "";
> }
> // Hashtable for custom parameters
> Hashtable params = new Hashtable();
> params.put("test",new Timestamp(System.currentTimeMillis()));
>
> CmsUser user = null;
> try {
> user = cms.addWebUser( userName, // Username
> password1, // Password
> group, // Default Group
> "Web User", // Comment
> params // Params Hashtable
> );
> user.setFirstname( firstName );
> user.setLastname( lastName );
> user.setEmail( email );
> cms.writeWebUser( user ); // Write changes to DB.
> }
> catch (Exception e) {
> e.printStackTrace(new PrintWriter(out));
> }
> %>
-----Message d'origine-----
De : opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] De la part de Christian
Steinert
Envoyé : mercredi 7 février 2007 19:27
À : The OpenCms mailing list
Objet : Re: [opencms-dev] Has anyone created a Web User self
registration JSP???
> I would just create my own JSP if I could find out how the passwords
> are encrypted with OpenCms...???
>
Why do you need this?I have not used web users until now, but there
should be a setPassword method for them, right? And if it exists, you
should hand over the unencrypted password as it is.
___
The principle should be as follows:
1. - when you create a new web user you set their password in plain text
and opencms creates a hash of the password and stores that hash in the
database
2. - Whenever your users log in, you ask opencms to check the password
and opencms will create a hash of the password that was entered during
login and compare that hash with the hash of the stored password. That's
at least how it should be.
For these operations there should be methods in opencms. I don't think
that you have to encrypt the passwords yourself.
christian
______________________________________________________________________
XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130
_______________________________________________
This mail is sent to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please
visit http://lists.opencms.org/mailman/listinfo/opencms-dev
More information about the opencms-dev
mailing list