472,119 Members | 1,596 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Problems about send automatic email with a random password

How can I use this random password code, and then insert the password into email which is sent to the user after the registration has been finished?
thx


[HTML]<html>
<head>
<title>javascript: Password Generator</title>

<style type="text/css">
input, select { font-family: Verdana, Arial, sans-serif;
font-size: 16pt;
font-weight: bold;
}
</style>

<script language="JavaScript">

function GeneratePassword() {

if (parseInt(navigator.appVersion) <= 3) {
alert("Sorry this only works in 4.0+ browsers");
return true;
}

var length=8;
var sPassword = "";
length = document.aForm.charLen.options[document.aForm.charLen.selectedIndex].value;

var noPunction = (document.aForm.punc.checked);
var randomLength = (document.aForm.rLen.checked);

if (randomLength) {
length = Math.random();

length = parseInt(length * 100);
length = (length % 7) + 6
}


for (i=0; i < length; i++) {

numI = getRandomNum();
if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }

sPassword = sPassword + String.fromCharCode(numI);
}

document.aForm.passField.value = sPassword

return true;
}

function getRandomNum() {

// between 0 - 1
var rndNum = Math.random()

// rndNum from 0 - 1000
rndNum = parseInt(rndNum * 1000);

// rndNum from 33 - 127
rndNum = (rndNum % 94) + 33;

return rndNum;
}

function checkPunc(num) {

if ((num >=33) && (num <=47)) { return true; }
if ((num >=58) && (num <=64)) { return true; }
if ((num >=91) && (num <=96)) { return true; }
if ((num >=123) && (num <=126)) { return true; }

return false;
}

</script>

<h2>javascript: Password Generator</h2>

<p><form name="aForm">
<table>

<tr>
<td>Generated Password:<br />
<input type="text" name="passField" value="" size="15"><br /></td>

<td># of chars<br />
<select name="charLen">
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8" selected>8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
</select>

</td>
</tr>

<tr>
<td><p><input type="checkbox" name="punc" checked> No Punction Marks <br />
<input type="checkbox" name="rLen"> Random Length (6 - 12) <br /></p></td>
<td>&nbsp;</td>
</tr>

<tr><td colspan="2" align="center">&nbsp;</td></tr>

<tr><td colspan="2" align="center">
<p><input type="button" value=" Generate Password " onClick="GeneratePassword()"></p></td>
</tr>
</table>[/HTML]
Mar 14 '07 #1
2 1884
r035198x
13,262 8TB
How can I use this random password code, and then insert the password into email which is sent to the user after the registration has been finished?
thx


<html>
<head>
<title>javascript: Password Generator</title>

<style type="text/css">
input, select { font-family: Verdana, Arial, sans-serif;
font-size: 16pt;
font-weight: bold;
}
</style>

<script language="JavaScript">

function GeneratePassword() {

if (parseInt(navigator.appVersion) <= 3) {
alert("Sorry this only works in 4.0+ browsers");
return true;
}

var length=8;
var sPassword = "";
length = document.aForm.charLen.options[document.aForm.charLen.selectedIndex].value;

var noPunction = (document.aForm.punc.checked);
var randomLength = (document.aForm.rLen.checked);

if (randomLength) {
length = Math.random();

length = parseInt(length * 100);
length = (length % 7) + 6
}


for (i=0; i < length; i++) {

numI = getRandomNum();
if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }

sPassword = sPassword + String.fromCharCode(numI);
}

document.aForm.passField.value = sPassword

return true;
}

function getRandomNum() {

// between 0 - 1
var rndNum = Math.random()

// rndNum from 0 - 1000
rndNum = parseInt(rndNum * 1000);

// rndNum from 33 - 127
rndNum = (rndNum % 94) + 33;

return rndNum;
}

function checkPunc(num) {

if ((num >=33) && (num <=47)) { return true; }
if ((num >=58) && (num <=64)) { return true; }
if ((num >=91) && (num <=96)) { return true; }
if ((num >=123) && (num <=126)) { return true; }

return false;
}

</script>

<h2>javascript: Password Generator</h2>

<p><form name="aForm">
<table>

<tr>
<td>Generated Password:<br />
<input type="text" name="passField" value="" size="15"><br /></td>

<td># of chars<br />
<select name="charLen">
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8" selected>8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
</select>

</td>
</tr>

<tr>
<td><p><input type="checkbox" name="punc" checked> No Punction Marks <br />
<input type="checkbox" name="rLen"> Random Length (6 - 12) <br /></p></td>
<td>&nbsp;</td>
</tr>

<tr><td colspan="2" align="center">&nbsp;</td></tr>

<tr><td colspan="2" align="center">
<p><input type="button" value=" Generate Password " onClick="GeneratePassword()"></p></td>
</tr>
</table>
This is a Java forum not a Javascript forum.

Moved to Javascript forum.
Mar 14 '07 #2
hi dear
you have 2 options.

1-you can use the javascript to open the default web client like outlook in the client computer
complete correct code
[HTML]
<html>
<head>
<title>javascript: Password Generator</title>

<style type="text/css">
input, select { font-family: Verdana, Arial, sans-serif;
font-size: 16pt;
font-weight: bold;
}
</style>

<script language="JavaScript">

function GeneratePassword() {

if (parseInt(navigator.appVersion) <= 3) {
alert("Sorry this only works in 4.0+ browsers");
return true;
}

var length=8;
var sPassword = "";
length = document.aForm.charLen.options[document.aForm.charLen.selectedIndex].value;

var noPunction = (document.aForm.punc.checked);
var randomLength = (document.aForm.rLen.checked);

if (randomLength) {
length = Math.random();

length = parseInt(length * 100);
length = (length % 7) + 6
}


for (i=0; i < length; i++) {

numI = getRandomNum();
if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }

sPassword = sPassword + String.fromCharCode(numI);
}

setMailLinkHref('myLink','you@yourmail.com','rando m password',sPassword)
document.aForm.passField.value = sPassword

return true;
}

function getRandomNum() {

// between 0 - 1
var rndNum = Math.random()

// rndNum from 0 - 1000
rndNum = parseInt(rndNum * 1000);

// rndNum from 33 - 127
rndNum = (rndNum % 94) + 33;

return rndNum;
}

function checkPunc(num) {

if ((num >=33) && (num <=47)) { return true; }
if ((num >=58) && (num <=64)) { return true; }
if ((num >=91) && (num <=96)) { return true; }
if ((num >=123) && (num <=126)) { return true; }

return false;
}

function setMailLinkHref(elmId,to,subj,msg)
{
oLink = document.getElementById(elmId);
str = 'mailto:'+to+'?subject='+subj+'&body='+msg;
oLink.href = str;
oLink.innerHTML = 'send mail <b>'+msg+'</b>';
}
</script>

<h2>javascript: Password Generator</h2>

<p><form name="aForm">
<table>

<tr>
<td>Generated Password:<br />
<input type="text" name="passField" value="" size="15"><br /></td>

<td># of chars<br />
<select name="charLen">
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8" selected>8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
<option value="13">13
<option value="14">14
<option value="15">15
</select>

</td>
</tr>

<tr>
<td><p><input type="checkbox" name="punc" checked> No Punction Marks <br />
<input type="checkbox" name="rLen"> Random Length (6 - 12) <br /></p></td>
<td>&nbsp;</td>
</tr>

<tr><td colspan="2" align="center">
<a href="#" id="myLink"></a>
</td>
</tr>

<tr><td colspan="2" align="center">
<p><input type="button" value=" Generate Password " onClick="GeneratePassword()"></p></td>
</tr>
</table>[/HTML]

i think its not great way to do it .i suggest you try to generate and send the random password with server side scripts like php

2-you can use ajax to send this message without refreshing client page with server side sending usage.
Mar 14 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by PHP | last post: by
3 posts views Thread by zeedan | last post: by
reply views Thread by Adam Carpenter | last post: by
4 posts views Thread by vercingetorix52 | last post: by
8 posts views Thread by Katash | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.