2013-07-05 73 views
0

我发现了一个密码生成器,并希望有一个表格,允许用户注册,但如果他们想要生成密码,他们可以按生成密码,并填写文本输入框密码。PHP密码生成表格形式

然后,我希望他们能够按下注册,它将所有的表单数据与手动设置的密码或生成的密码发送到表单提交。

任何想法,我可以把窗体内的形式与它是有效的HTML?

我的代码如下:

<form id="register" action="registerprocess.php" method="post"> 
    <span><strong>Please note all fields are required</strong></span><br /><br /> 
    <label for="fullname">Full Name: </label><input type="text" id="fullname" name="fullname" required><br /> 
    <label for="email">Email Address: </label><input type="email" id="email" name="email" required><br /><br /> 
    <label for="manualpass">User-Defined Password: </label><input type="text" id="manualpass" name="manualpass" required><br /> 
    <?php 

    $f_contents = file("..\sec\possiblewords.txt"); 
    $word = $f_contents[rand(0, count($f_contents) - 1)]; 

    function vowelreplacement() { 
     global $word; 
     $string = $word; 
     $trans = array("a" => "4", "e" => "3", "i" => "1", "o" => "0"); 

     return strtr($string, $trans); 
    }   

    $generatedpassword = vowelreplacement(); 

    ?> 
    <form id="vowelremover" method="post">   
     <label for="generatedpass">Generated Password: </label><input type="text" id="generatedpass" name="generatedpass" value=<?php echo $generatedpassword;?> required><input type="submit" value="Generate Password"> 
    </form> 
    <input type="submit" value="register"> 
</form> 
+0

,你能否告诉我们在一个表格形式的代码?它可能被压缩成“只是一种形式”。 –

+0

这已经为你完成:) – AaronHatton

+0

这不会是非常安全的,因为你公开所有你生成的密码很容易! – Nanne

回答

0

实现jQuery插件,然后执行以下操作:

ajax.php(上如服务器test.com)

<?php 

$f_contents = file("..\sec\possiblewords.txt"); 
$word = $f_contents[rand(0, count($f_contents) - 1)]; 

function vowelreplacement() { 
    global $word; 
    $string = $word; 
    $trans = array("a" => "4", "e" => "3", "i" => "1", "o" => "0"); 

    return strtr($string, $trans); 
}   

echo vowelreplacement(); 
(在这里您将您的形式PHP文件)

form.php的

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> 

<form id="register" action="registerprocess.php" method="post"> 
    <span><strong>Please note all fields are required</strong></span><br /><br /> 
    <label for="fullname">Full Name: </label><input type="text" id="fullname" name="fullname" required><br /> 
    <label for="email">Email Address: </label><input type="email" id="email" name="email" required><br /><br /> 
    <label for="manualpass">User-Defined Password: </label><input type="text" id="manualpass" name="manualpass" required><br /> 

    <form id="vowelremover" method="post">   
     <label for="generatedpass">Generated Password: </label><input type="text" id="generatedpass" name="generatedpass" value=<?php echo $generatedpassword;?> required><input type="submit" value="Generate Password"> 
    </form> 
    <input type="submit" value="register"> 
</form> 

<script type="text/javascript"> 

$(function() { 

    $("#vowelremover").submit(function() { 

     $("#generatedpass").load("http://test.com/ajax.php"); 

     return false; 
    }); 
}); 

</script> 
0

您可以通过AJAX新生成的密码加载到密码字段。用户可以单击密码字段旁边的链接以使用生成的密码填写该字段。

另一种选择是用javascript生成密码并将其放入字段中。那么你不需要php脚本来生成js就可以简化了。

1

如果你想用PHP生成你的密码,你必须处理AJAX,然后把你的Ajax响应的结果放到使用Javascript的输入中。

要么也有很多JavaScript的密码生成器,可以帮助您与此

-1

的jQuery插件有许多功能,可以简化您的任务。看到HERE你正在寻找的样品(刷新表单的一个元素)

-4

我已经远远好得多,功能齐全的VB代码,随机密码生成器。这是我自己编写的VB Express程序。用户可以选择密码长度并从上限,下限,数字或特殊字符中选择。您可以生成8至25个字符的无尽密码。这里是代码和.RAR文件来下载完整的程序。最好的是...它的免费!

\\\======================================================================\\\ 
Option Explicit On 
'--------------------------------------------------------------------- 
'--------------------------------------------------------------------- 
'---------------------- Password Generator ® ------------------------- 
'---------------------- Author: Chirag Patel ------------------------- 
'---------------------- Current Version: 1.x ------------------------- 
'---------------------- Date: August, 14, 2015 ----------------------- 
'---------------------- License: FREE License Program ---------------- 
'--------------------------------------------------------------------- 
'--------------------------------------------------------------------- 

Public Class frmPassGen 
    'Declearing main intiger which will hold password 
    Dim Letters As New List(Of Integer) 

Public Function Info() 
    'This button provide information about author 
    Dim Infor As String 

    Infor = MsgBox("Program: Password Generator ®" & _ 
        vbCrLf & "---------------------------------" & _ 
        vbCrLf & "Version: 1.0" & _ 
        vbCrLf & "Programmer: Chirag Patel" & _ 
        vbCrLf & " " & _ 
        vbCrLf & "Legal Verbiage" & _ 
        vbCrLf & "-----------------" & _ 
        vbCrLf & "This program is FREE License program." & _ 
        vbCrLf & " " & _ 
        vbCrLf & "Thank you." & _ 
        vbCrLf & "Chirag Patel", MsgBoxStyle.Information, "Password Generator") 
    cmbLength.Focus() 
End Function 

Public Function Clear() 
    On Error Resume Next 
    'Clears ALL 
    cmbLength.Text = "000" 
    cmbLength.Focus() 
    txtPassword.Text = "... Your Password ..." 
    chkUpper.Checked = False 
    chkLower.Checked = False 
    chkNumber.Checked = False 
    chkSpecial.Checked = False 
    txtLPass.Text = "" 
    cmbNpass.Text = "000" 
End Function 

Public Function Upper() 
    'Add ASCII Codes For Upper Case Letters 
    For i As Integer = 65 To 90 
     Letters.Add(i) 
    Next 
End Function 

Public Function Lower() 
    'Add ASCII Codes For Lower Case Letters 
    For i As Integer = 97 To 122 
     Letters.Add(i) 
    Next 
End Function 

Public Function Numbers() 
    'Add ASCII Codes For Numbers 
    For i As Integer = 48 To 57 
     Letters.Add(i) 
    Next 
End Function 

Public Function Special() 
    'Add ASCII Codes For Special Characters 
    For i As Integer = 33 To 47 
     Letters.Add(i) 
    Next 
End Function 

Public Function uRemove() 
    Dim rRnd As New Random 
    Dim rSB As New System.Text.StringBuilder 
    Dim trPass As Integer 
    'Remove ASCII code for Upper case letters 
    For i As Integer = 65 To 90 
     Letters.Remove(i) 
    Next 
    'Remove ASCII Codes For Lower Case Letters 
    For i As Integer = 97 To 122 
     Letters.Remove(i) 
    Next 
    'Remove ASCII Codes For Numbers 
    For i As Integer = 48 To 57 
     Letters.Remove(i) 
    Next 
    'Remove ASCII Codes For Special Characters 
    For i As Integer = 33 To 47 
     Letters.Remove(i) 
    Next 
    'Remove cache 
    For count As Integer = -1 To Val(cmbLength.Text) 

     trPass = rRnd.Next(0, Letters.Count) 
     rSB.Append(Chr(Letters(trPass))) 

    Next 
    txtPassword.Text = rSB.ToString 
End Function 

Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click 
    On Error Resume Next 
    'Exit Program 
    Me.Close() 
    End 
End Sub 

Private Sub txtPassword_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPassword.KeyDown 
    On Error Resume Next 
    'Doesn't allow to change password 
    txtPassword.Text = "" 
    MsgBox("You cannot change password here.", MsgBoxStyle.Information, "Password Generator") 
    txtPassword.Text = "... Your Password ..." 
    cmbLength.Text = "000" 
    cmbNpass.Text = "000" 
    cmbLength.Focus() 
End Sub 

Private Sub frmPassGen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    On Error Resume Next 
    'Default Settings 
    cmbLength.Text = "000" 
    cmbNpass.Text = "000" 
    cmdOK.Enabled = False 
    txtPassword.Text = "... Your Password ..." 
    cmbLength.Focus() 
    lbltTime.Text = TimeOfDay 
    Me.Text = "Password Generator - " & Format(Date.Now, "dddd, MM-dd-yyyy") 
End Sub 

Private Sub cmbLength_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbLength.SelectedIndexChanged 
    On Error Resume Next 
    'Enable Generate Button 
    If cmbLength.Text = "000" Then 
     cmdOK.Enabled = False 
    Else 
     cmdOK.Enabled = True 
    End If 
End Sub 

Private Sub cmdInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdInfo.Click 
    On Error Resume Next 
    'Display Program Info 
    Call Info() 
End Sub 
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click 
    On Error Resume Next 
    For i As Integer = 0 To Val(cmbNpass.Text)    'Number of passwords need to generate 

     'Disabled OK (Generate) Button when no options are selected 
     If chkLower.Checked = False And chkNumber.Checked = False And chkSpecial.Checked = False And chkUpper.Checked = False Then 
      MsgBox("Please select at list one of the four options to generate new random password.", MsgBoxStyle.Information, "...Password Generator") 
      cmbLength.Focus() 
      cmdOK.Enabled = False 
     End If 

     'Decleration of Variables 
     Dim Rnd As New Random       ' Generates Random Strings 
     Dim SB As New System.Text.StringBuilder   ' Bings the String generated by Rnd 
     Dim tPass As Integer       ' Temp Variable to hold the generated string in temp continer 

     'Condition... 
     If cmbLength.Text = "000" And cmbNpass.Text = "000" Then 
      Beep() 
      MsgBox("You must select the length and numbers password.", MsgBoxStyle.Information, "Password Generator") 
     Else 
      cmdOK.Enabled = True 
     End If 
     'Creating password string... 

     For count As Integer = 1 To Val(cmbLength.Text)  'Length of password 

      tPass = Rnd.Next(0, Letters.Count) 
      SB.Append(Chr(Letters(tPass))) 
      Resume 
     Next 
     If Val(i) = 1 Then          'One Password Generated 
      txtPassword.Text = SB.ToString 
     Else 
      txtPassword.Text = SB.ToString      'More Password Generated 
      txtLPass.Text += txtPassword.Text & vbNewLine 
     End If 
    Next 


    'Disabled OK (Generate) Button when no options are selected 
    If chkLower.Checked = False And chkNumber.Checked = False And chkSpecial.Checked = False And chkUpper.Checked = False Then 
     cmbLength.Text = "000" And cmbNpass.Text = "000" 
    End If 
End Sub 

Private Sub cmbLength_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbLength.KeyDown 
    On Error Resume Next 
    'Doesn't allow users to alter the value in selection (drop down box) 
    cmbLength.Text = "" 
    cmbLength.Text = "000" 
    MsgBox("Sorry, you cannot alter the value in this area.", MsgBoxStyle.Information, "Password Generator") 
End Sub 

Private Sub chkUpper_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkUpper.CheckedChanged 
    If chkUpper.Checked = True Then 
     Call Upper() 
    Else 
     'Remove ASCII code for Upper case letters 
     For i As Integer = 65 To 90 
      Letters.Remove(i) 
     Next 
    End If 
End Sub 

Private Sub chkLower_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkLower.CheckedChanged 
    If chkLower.Checked = True Then 
     Call Lower() 
    Else 
     'Remove ASCII Codes For Lower Case Letters 
     For i As Integer = 97 To 122 
      Letters.Remove(i) 
     Next 
    End If 
End Sub 

Private Sub chkNumber_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkNumber.CheckedChanged 
    If chkNumber.Checked = True Then 
     Call Numbers() 
    Else 
     'Remove ASCII Codes For Numbers 
     For i As Integer = 48 To 57 
      Letters.Remove(i) 
     Next 
    End If 
End Sub 

Private Sub chkSpecial_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSpecial.CheckedChanged 
    On Error Resume Next 
    'Checks if the Special Checkbox is checked 
    If chkSpecial.Checked = True Then 
     Call Special() 
    Else 
     'Remove ASCII Codes For Special Characters 
     For i As Integer = 33 To 47 
      Letters.Remove(i) 
     Next 
    End If 
End Sub 

Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click 
    On Error Resume Next 
    'Call Clear 
    Call Clear() 
End Sub 

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 
    lbltTime.Text = TimeOfDay 
End Sub 

Private Sub txtLPass_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtLPass.KeyDown 
    On Error Resume Next 
    'Doesn't allow Edit... 
    MsgBox("You cannot alter the password here.", MsgBoxStyle.Information, "Password Generator") 
    Call Clear() 
End Sub 

Private Sub cmbNpass_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbNpass.SelectedIndexChanged 
    On Error Resume Next 
    'Enable Generate Button 
    If cmbNpass.Text = "000" Then 
     cmdOK.Enabled = False 
    Else 
     cmdOK.Enabled = True 
    End If 
End Sub 

末级

+0

“更好的解决方案”可能是您的意见。但是,我们不要放下别人的解决方案。另外,你发布了这个问题,并在3年​​前回答了(接受*的答案)。而且......你不必谈论你的解决方案是免费的(而且这不是推广你的软件的地方)。最后:您可能需要修正一些格式错误。 –