You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Barry Books <bf...@mac.com> on 2005/03/23 01:18:54 UTC

Sha1 password component

I'm writing a component that does challenge/response authentication. 
The idea is you have an input element like

<input jwcid="@Sha1Password" value="ognl:password" />

On form submit this component takes a challenge and the password runs 
sha1 on it and puts the result back into the form field. This way (if 
javascript is enabled) clear text passwords are not sent over the 
Internet.

I have it working but I can't figure out a good way to handle the 
onSubmit action because I need that on the form element containing the 
input tag.

Is there a way in Tapestry to find the id of the form that contains my 
input element? Then on the javascript side I could stuff in the 
onSubmit attribute into the form. The problem with this is some other 
component  could have the same idea.

or

Would it be better to create a new type of form that allows onSubmit 
functions to be registered. I think I would still need to get the form 
id though.

I tried ognl:container.id but it does not do what I expected.

barry


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Sha1 password component

Posted by Barry Books <bf...@mac.com>.
That was the problem. I didn't realize the java was now including the script.

As soon as I work out the details I'll package up the code and put it someplace. 

To use it the html looks like this

<form jwcid="@Form" listener="ognl:listeners.login">
  User Name <input type="text" jwcid="@TextField" value="ognl:userName" /><br />
  Password <input jwcid="@Sha1Password" password="ognl:password" salt="ognl:salt"  /> <br />
  <input type="submit" value="Login" />        
</form>

So far I'm very impressed with Tapestry's javascript support. It seems you can actually make reusable components that use javascript.

Thanks
barry

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Sha1 password component

Posted by Andreas Andreou <an...@di.uoa.gr>.
What you've done so far seems correct...
Can you also post the jwc of your component
as well as the html from where you use your component?
Maybe you're also including a <span jwcid="@Script" 
script="Sha1Password.script"/>
in these files,
which is now not needed 'cause you're including the script from the java 
code...
Andreas

Barry Books wrote:

>Thanks for the tips. The Javascript support in Tapestry is much more sophisticated than I thought.
>
>I looked at the palette component and I got pretty far but I have one last problem
>
>I have this function to run onSubmit
>
>function replacePassword() {
>	${Password}.value = hpw(${Password}.value,${Salt}.value);
>}
>
>I added this to the top of my script file
>
><input-symbol key="formName" class="java.lang.String" required="yes"/>
>
>
><let key="formPath">
>  document.${formName}
></let>
>
>
><let key="Salt">
>  ${formPath}.Salt
></let>
><let key="Password">
>  ${formPath}.Password
></let>
>
>and this to my java file
>
>	IForm form = Form.get(getPage().getRequestCycle());
>        Body body = Body.get(cycle);
>
>        _symbols = new HashMap(10);
>        System.out.println("formname = " + form.getName());
>        _symbols.put("formName", form.getName());
>
>        if (_script == null)
>        {
>            IEngine engine = getPage().getEngine();
>            IScriptSource source = engine.getScriptSource();
>
>            IResourceLocation scriptLocation =
>                getSpecification().getSpecificationLocation().getRelativeLocation("Sha1Password.script");
>
>            _script = source.getScript(scriptLocation);
>        }
>
>        if (!cycle.isRewinding())
>        {
>        	_script.execute(cycle, body, _symbols);
>    		
>        }
>
>        form.addEventHandler(FormEventType.SUBMIT,"replacePassword");
>
>
>Now I get 
>Script symbol 'formName' is required, but not specified.
>
>What's the trick to setting an input-symbol?
>
>Thanks
>barry
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Sha1 password component

Posted by Barry Books <bf...@mac.com>.
Thanks for the tips. The Javascript support in Tapestry is much more sophisticated than I thought.

I looked at the palette component and I got pretty far but I have one last problem

I have this function to run onSubmit

function replacePassword() {
	${Password}.value = hpw(${Password}.value,${Salt}.value);
}

I added this to the top of my script file

<input-symbol key="formName" class="java.lang.String" required="yes"/>


<let key="formPath">
  document.${formName}
</let>


<let key="Salt">
  ${formPath}.Salt
</let>
<let key="Password">
  ${formPath}.Password
</let>

and this to my java file

	IForm form = Form.get(getPage().getRequestCycle());
        Body body = Body.get(cycle);

        _symbols = new HashMap(10);
        System.out.println("formname = " + form.getName());
        _symbols.put("formName", form.getName());

        if (_script == null)
        {
            IEngine engine = getPage().getEngine();
            IScriptSource source = engine.getScriptSource();

            IResourceLocation scriptLocation =
                getSpecification().getSpecificationLocation().getRelativeLocation("Sha1Password.script");

            _script = source.getScript(scriptLocation);
        }

        if (!cycle.isRewinding())
        {
        	_script.execute(cycle, body, _symbols);
    		
        }

        form.addEventHandler(FormEventType.SUBMIT,"replacePassword");


Now I get 
Script symbol 'formName' is required, but not specified.

What's the trick to setting an input-symbol?

Thanks
barry

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Sha1 password component

Posted by Andreas Andreou <an...@di.uoa.gr>.
The Form class has a static method

public static IForm <http://jakarta.apache.org/tapestry/doc/api/org/apache/tapestry/IForm.html> *get*(IRequestCycle <http://jakarta.apache.org/tapestry/doc/api/org/apache/tapestry/IRequestCycle.html> cycle)
which returns the instance of the active IForm

>From then on, check out the following methods of IForm:
getName() to get the name of the form (it can then be used in javascript)
and
IForm.addEventHandler(FormEventType, String)
which would allow you to add an onSubmit javascript such as "return checkForm(this);"
and so there would be no need to get the name or the id of the form...
Have fun,
Andreas



Barry Books wrote:

> I'm writing a component that does challenge/response authentication. 
> The idea is you have an input element like
>
> <input jwcid="@Sha1Password" value="ognl:password" />
>
> On form submit this component takes a challenge and the password runs 
> sha1 on it and puts the result back into the form field. This way (if 
> javascript is enabled) clear text passwords are not sent over the 
> Internet.
>
> I have it working but I can't figure out a good way to handle the 
> onSubmit action because I need that on the form element containing the 
> input tag.
>
> Is there a way in Tapestry to find the id of the form that contains my 
> input element? Then on the javascript side I could stuff in the 
> onSubmit attribute into the form. The problem with this is some other 
> component  could have the same idea.
>
> or
>
> Would it be better to create a new type of form that allows onSubmit 
> functions to be registered. I think I would still need to get the form 
> id though.
>
> I tried ognl:container.id but it does not do what I expected.
>
> barry
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org