codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Random Password Generator.. problem in file handling  shilpa09 at 05:50 on Monday, June 28, 2010
 

Hi there...
actually i am working on a project "random password generator". What basically is to be done in this project is to generate user password for the username randomly he has provided. Then, this password is to be stored in a text file in the following manner
UserName Password
ABCD JU12H6
Sdjksj HJudfdsfd
Now my problem is that every time I just try to generate a new password, either a new file is made or the heading is rewritten again and again or if I just try to change the variables true and false, then the username and password headings are not printed. Please help. If someone knows how to do this using if-else method then please tell me, how it can be done?
The code is attached.


[code]
<html>
<HEAD>

<SCRIPT LANGUAGE="JavaScript">
function GetSelectedItem()
{
chosen = "";
for (i = 0; i <3; i++)
{
if (document.myform.opt.checked)
{
chosen = document.myform.opt.value;
}
}

if (chosen == "")
{
alert("Choose your password type")
exit;
}
return chosen;
}

function getPassword(usnm,length,opti)
{
if(usnm=="")
{
alert("Enter user name");
exit;
}
var optsel=GetSelectedItem();
var num = "0123456789";
var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var alphanum = "0123456789abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var pass = "";
if(length!=5 && length!=6 && length!=7 && length!=8 && length!=9 && length!=10)
{
alert("Enter password length between 5 and 10");
exit;
}
else
{
if (optsel==1)
{
for(x=0;x<length;x++)
{
i = Math.floor(Math.random() * 72);
pass += alphanum.charAt(i);
}
}

else if (optsel==2)
{
for(x=0;x<length;x++)
{
i = Math.floor(Math.random() * 10);
pass += num.charAt(i);
}
}

else if (optsel==3)
{
for(x=0;x<length;x++)
{
i = Math.floor(Math.random() * 52);
pass += alpha.charAt(i);
}
}
WriteToFile(usnm,pass);
return pass;
}
}
function WriteToFile(usnm,pass)
{
try
{
var fso1=new ActiveXObject("Scripting.FileSystemObject");
var pf1=fso1.OpenTextFile("Password.text",8);
//if(pf=='false')

//var fso=new ActiveXObject("Scripting.FileSystemObject");
//dspf=fso.OpenTextFile("/forum/Password.txt",8,true);
//pf.WriteLine("Username\t\tPassword");
pf1.WriteLine(usnm+'\t\t'+pass);
pf1.Close();
}
catch(err)
{
var fso=new ActiveXObject("Scripting.FileSystemObject");
pf=fso.CreateTextFile("/forum/Password.txt",8,false);
pf.WriteLine("Username\t\tPassword")
pf.WriteLine(usnm+'\t\t\t'+pass);
pf.Close();
}


// fso= null;
/*
else
{
//var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("/forum/DPassword.txt", true);
s.WriteLine('Username\t\tPassword');
//while(s.next())
s.WriteLine(usnm+'\t\t'+pass);
s.Close();
}*/

/*var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile("/forum/DPassword.txt",8, true);
s.WriteLine('Username\t\tPassword');
//while(s.next())
s.WriteLine(usnm+'\t\t'+pass);
s.Close();*/
}

</script>

</HEAD>

<BODY>

<center>
<table width=80% border=0>
<tr align=center>
<td>
<form name="myform">
<table border=0>
<tr>
<td>
Enter Username:
</td>
<td>
<input type=text name=userName value="" size=20>
</td>
</tr>
<tr>
<td>
Chooose Password type:</td>
<td>
<input type="radio" name="opt" value="1" >Alphanumeric
<input type="radio" name="opt" value="2">Numeric
<input type="radio" name="opt" value="3">Alphabetic
</td>
</tr>
<tr>
<td>
</tr>
<tr>
<td>
Password length:
</td>
<td>
<input type=text name=passwordLength value="" size=2>
</td>
</tr>
</table>
</td>
</tr>
<tr align=center>
<td>
New password:
<input type=text name=password size=20>
<br>
<input type=button value="Generate password" onClick="document.myform.password.value =
getPassword(document.myform.userName.value,document.myform.passwordLength.value,
document.myform.opt.checked);">
</form>
</td>
</tr>
</table>
</center>


</html>
[/code]








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Random Password Generator.. problem in file handling
•  Re: Difference between two dates including From & To date
•  Re: dereferenceing a string to a constant name
•  Re: PHP swapping images
•  Re: JavaScript: Not working in Firefox 3.x
•  Re: Need Javascript Multiple sidebar menu with sliding effects
•  insert datepicker on each row
•  insert datepicker on each row
•  Microsoft JET Database Engine (0x80040E07) Data type mismatch in criteria expression.


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010