Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > กระทู้สำหรับภาษาต่าง ๆ > การทำ Login แบบ เช็คตัวพิมพ์เล็กพิมพ์ใหญ่ ทำได้มั้ยครับ จากโค๊ดนี้ รบกวนผู้รู้แนะนำแนวทางหน่อยครับ



การทำ Login แบบ เช็คตัวพิมพ์เล็กพิมพ์ใหญ่ ทำได้มั้ยครับ จากโค๊ดนี้ รบกวนผู้รู้แนะนำแนวทางหน่อยครับ

 
Topic : 132525



โพสกระทู้ ( 86 )
บทความ ( 0 )



สถานะออฟไลน์



การทำ Login แบบ เช็คตัวพิมพ์เล็กพิมพ์ใหญ่ ทำได้มั้ยครับ จากโค๊ดนี้ รบกวนผู้รู้แนะนำแนวทางหน่อยครับ

Code (C#)
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Test
{

   
    public partial class Login : System.Web.UI.Page
    {
 SqlConnection conn = new SqlConnection("Data Source=ARTEMIS\\SQL2014;Initial Catalog=SvlITDB;User ID=it;Password=Tigers1234");

        protected void Page_Load(object sender, EventArgs e)
        {
            

        }
        #region Button1_Click
        protected void Button1_Click(object sender, EventArgs e)
        {
            SqlCommand sqlcom = new SqlCommand("Select * From Usr where UsrName='" + TextBox1.Text + "' and Password='" + TextBox2.Text + "'", conn);
            conn.Open();
            SqlDataReader reader = sqlcom.ExecuteReader();
           

            if (TextBox1.Text == "IT" & TextBox2.Text == "Tigers1234" ) {
                string scriptText = "alert('             . . . . . . . . . <เข้าสู่ระบบแล้ว : ยินดีต้อนรับ ADMIN > . . . . . . . . . '); window.location='" + Request.ApplicationPath + "ShowIT.aspx'";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", scriptText, true);

            }
            if (TextBox1.Text == "svlit" & TextBox2.Text == "tigers@1234") {
                string scriptText = "alert('             . . . . . . . . . <เข้าสู่ระบบแล้ว : ยินดีต้อนรับ ADMIN > . . . . . . . . . '); window.location='" + Request.ApplicationPath + "ShowIT.aspx'";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", scriptText, true);
            }

           else if (reader.Read())
            {
                
                Session["DeptName"] = reader["DeptName"].ToString();
                Session["Tel"] = reader["Tel"].ToString();

                string scriptText = "alert('                            . . . . . . . . . <เข้าสู่ระบบแล้ว > . . . . . . . . . '); window.location='" + Request.ApplicationPath + "default.aspx'";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", scriptText, true);
            }
            else
            {

                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Myscript", "alert('UserName หรือ Password กรุณากรอกให้ถูกต้องด้วยค่ะ !!!')", true);

            }
            conn.Close();
        }
        #endregion
        protected void Button2_Click(object sender, EventArgs e)
        {
            TextBox1.Text = "";
            TextBox2.Text = "";
          
        }
    }
}




Tag : Web (ASP.NET), C#


Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2018-11-09 13:28:41 By : wiraphon View : 728 Reply : 4
 

 

No. 1



โพสกระทู้ ( 328 )
บทความ ( 0 )



สถานะออฟไลน์


where เอาเฉพาะ username มาก่อนครับ ค่อยเอามาเปรียบเทียบหลังจาก query มาแล้ว
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-11-09 14:19:45 By : Luz
 


 

No. 2



โพสกระทู้ ( 86 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : Luz เมื่อวันที่ 2018-11-09 14:19:45
รายละเอียดของการตอบ ::

หมายถึงแบบนี้หรอครับ แล้วมันเอามาเปรียบในไหนรูปแบบไหนครับ
Code (C#)
 SqlCommand sqlcom = new SqlCommand("Select * From Usr where UsrName='" + TextBox1.Text + '", conn);


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-11-09 14:49:18 By : wiraphon
 


 

No. 3



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


รับข้อมูลนำมาคิวรี่ ให้ใช้ db tool ครับ อย่าต่อ string ตรงๆ แบบนั้น

https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlcommand.parameters?view=netframework-4.7.2


เช็คพิมพ์เล็กพิมพ์ใหญ่
https://stackoverflow.com/questions/44353157/sql-server-check-upper-case-or-lower-case-after-certain-character

หรือ
Code (C#)
SqlCommand cmd = new SqlCommand ("select COUNT(*) from UserTable where (CAST(User_Name as varbinary(50))=cast('"+ Login.UserName_value+"' as varbinary))  and (CAST(User_Password as varbinary(50))=cast('"+Login.UserPassword_value+"' as varbinary)),con);
con.Open();
string str = cmd.ExecuteScalar().ToString();
con.Close();
return str;



ประวัติการแก้ไข
2018-11-09 17:24:40
2018-11-09 17:34:21
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-11-09 17:16:55 By : Chaidhanan
 


 

No. 4



โพสกระทู้ ( 86 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 3 เขียนโดย : Chaidhanan เมื่อวันที่ 2018-11-09 17:16:55
รายละเอียดของการตอบ ::
ผมเอา รูปแบบของพี่มาประยุกค์แล้วถ้าไม่ดึง Session ไปด้วย มัน login ได้โดยเช็คตัวพิมพ์เล็กพิมพ์ใหญ่แต่ผมเอา Session เข้ามาเกี่ยวข้องด้วย กลับ Error หรือผมเขียนโค๊ดผิดหรอครับ
Code (C#)
            SqlCommand cmd = new SqlCommand("select count(*) from Usr where (CAST(UsrName as varbinary(50))=cast('" + TextBox1.Text + "' as varbinary))  and (CAST(Password as varbinary(50))=cast('" + TextBox2.Text + "' as varbinary))",conn);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();


            if (TextBox1.Text == "IT" & TextBox2.Text == "Tigers1234")
            {
                string scriptText = "alert('                               <เข้าสู่ระบบแล้ว : ยินดีต้อนรับ ADMIN >                   '); window.location='" + Request.ApplicationPath + "ShowIT.aspx'";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", scriptText, true);

            }
            if (TextBox1.Text == "svlit" & TextBox2.Text == "tigers@1234")
            {
                string scriptText = "alert('                               <เข้าสู่ระบบแล้ว : ยินดีต้อนรับ ADMIN >                   '); window.location='" + Request.ApplicationPath + "ShowIT.aspx'";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", scriptText, true);
            }

            else if (reader.Read())
            {
**************************************************************************************
                Session["DeptName"] = reader["DeptName"].ToString();
                Session["Tel"] = reader["Tel"].ToString();

**************************************************************************************
                string scriptText = "alert('                            . . . . . . . . . <เข้าสู่ระบบแล้ว > . . . . . . . . . '); window.location='" + Request.ApplicationPath + "default.aspx'";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", scriptText, true);
            }
            else
            {

                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Myscript", "alert('UserName หรือ Password กรุณากรอกให้ถูกต้องด้วยค่ะ !!!')", true);

            }
            conn.Close();


อันนี้เป็นส่วนที่ใช้ได้ปกติ
Code (C#)
            SqlConnection conn = new SqlConnection("Data Source=ARTEMIS\\SQL2014;Initial Catalog=SvlITDB;User ID=it;Password=Tigers1234;");
            SqlCommand cmd = new SqlCommand("select COUNT(*) from Usr where (CAST(UsrName as varbinary(50))=cast('" + TextBox1.Text + "' as varbinary))  and (CAST(Password as varbinary(50))=cast('" + TextBox2.Text + "' as varbinary))", conn) ;
            conn.Open();
             string str = cmd.ExecuteScalar().ToString();
 
         
            conn.Close();

            if (TextBox1.Text == "IT" & TextBox2.Text == "Tigers1234")
            {

                string scriptText = "alert('                            . . . . . . . . . <เข้าสู่ระบบแล้ว > . . . . . . . . . '); window.location='" + Request.ApplicationPath + "default.aspx'";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", scriptText, true);
            }
            else {
                string scriptText = "alert('                            . . . . . . . . . <ผิด > . . . . . . . . . '); window.location='" + Request.ApplicationPath + "TestTable.aspx'";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alertMessage", scriptText, true);

            }

fff


ประวัติการแก้ไข
2018-11-10 09:23:46
2018-11-10 09:25:32
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2018-11-10 09:10:40 By : wiraphon
 


   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : การทำ Login แบบ เช็คตัวพิมพ์เล็กพิมพ์ใหญ่ ทำได้มั้ยครับ จากโค๊ดนี้ รบกวนผู้รู้แนะนำแนวทางหน่อยครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่