一个简单的js密码验证记录

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        form>p>input{
            color: #999;
        }
        #ipt{
            color: #333;
        }
        span{
            color: #999;
        }
    

    </style>
</head>
<body>
    <form action="">
        <h2>世纪佳缘登录</h2>
        <p>账号:<input type="text" name="" id="text" value="请输入您的账号" placeholder></p>
        <p>密码:<input type="text" name="" id="ipt2" value="请输入您的密码" placeholder> <span>请输入6-16位的密码</span></p>
        <input type="button" value="提交" id="submit">
        <input type="reset" value="重置">
    </form>
    <script>
        var input = document.getElementById("text");
        var ipt = document.getElementById("ipt2");
        var span=document.querySelector("span");
        var submit=document.getElementById("submit")
        input.onfocus=function(){
            if(input.value!=""){
                this.value=""
            }
            this.style.color="#333"

        }
         input.onblur=function(){
            this.style.color="#999"
            if(this.value==""){
                this.value="请输入您的账号"
            }
        }

        ipt.onfocus=function(){
            if(input.value!=""){
                this.value=""
            }
            this.type="password"
            this.style.color="#333"
        }

            ipt.onblur = function(){


            if(this.value.length<6 || this.value.length>16){
                span.style.color="red"
                span.innerHTML="请出入正确的密码"
                
            }
            else{
                
                span.style.color="green"
                span.innerHTML="您输入正确"

            }
            
            
        }
        submit.onclick = function(){
            if(input.value=='123456'&&ipt.value=='123456')
            {
                alert('密码正确')
            }
            else{
                alert('密码错误,请输入正确的密码')
            }
        }

           

    </script>
</body>
</html>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
以下是用ASP.NET写一个简单的登录验证的示例代码: 1. 创建一个名为Login.aspx的页面,添加两个文本框和一个按钮,分别用于输入用户名、密码和登录操作。 ```html <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="WebApplication1.Login" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta charset="utf-8" /> <title>Login</title> <link href="Content/bootstrap.min.css" rel="stylesheet" /> <script src="Scripts/jquery-3.5.1.min.js"></script> <script src="Scripts/bootstrap.min.js"></script> </head> <body> <form id="form1" runat="server"> <div class="container"> <h2>Login</h2> <div class="form-group"> <label for="txtUsername">Username:</label> <input type="text" class="form-control" id="txtUsername" runat="server" /> </div> <div class="form-group"> <label for="txtPassword">Password:</label> <input type="password" class="form-control" id="txtPassword" runat="server" /> </div> <button type="submit" class="btn btn-primary">Login</button> </div> </form> </body> </html> ``` 2. 在Login.aspx.cs文件中添加以下代码,在按钮的Click事件中实现登录验证功能。 ```csharp using System; using System.Data.SqlClient; namespace WebApplication1 { public partial class Login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnLogin_Click(object sender, EventArgs e) { string username = txtUsername.Value.Trim(); string password = txtPassword.Value.Trim(); string connectionString = "Server=.;Database=Test;Trusted_Connection=True;"; SqlConnection connection = new SqlConnection(connectionString); try { connection.Open(); string sql = string.Format("SELECT COUNT(*) FROM Users WHERE Username='{0}' AND Password='{1}'", username, password); SqlCommand command = new SqlCommand(sql, connection); int count = (int)command.ExecuteScalar(); if (count > 0) { Response.Redirect("Welcome.aspx"); } else { Response.Redirect("Login.aspx"); } } catch (Exception ex) { Response.Write(ex.Message); } finally { connection.Close(); } } } } ``` 3. 在连接到数据库之前,需要先创建一个Test数据库,并在其中创建一个名为Users的表,用于存储用户名和密码。 ```sql CREATE DATABASE Test; USE Test; CREATE TABLE Users ( ID INT PRIMARY KEY IDENTITY(1,1), Username NVARCHAR(50) NOT NULL, Password NVARCHAR(50) NOT NULL ); INSERT INTO Users VALUES ('admin', '123456'); ``` 当用户点击登录按钮时,程序会根据输入的用户名和密码在数据库中查询,如果找到匹配的记录,则跳转到Welcome.aspx页面,否则提示登录失败并返回到Login.aspx页面。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值