Click here to Skip to main content
15,885,996 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone, i am still newbie in vb.net 2008
i am try to make change pasword form

what i want to do is when i click change pasword button then user must input old paswword , new pasword and confirm the new pasword
i am using sql server 2005 and my friend told me to use sqlcommandbuilder

anyone can help me ??



VB
Imports System.Data.SqlClient

Public Class frm_chPass
    Dim conn As SqlConnection
    Dim da As SqlDataAdapter, dt As New DataTable, dtv As New DataView

    Private Sub btn_exit Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
    Private Sub kunciobjek()
        txt_confirm.ReadOnly = True
        txt_new.ReadOnly = True
        txt_old.ReadOnly = True
    End Sub
    Private Sub bukaobjek()
        txt_confirm.ReadOnly = False
        txt_new.ReadOnly = False
        txt_old.ReadOnly = False
    End Sub

    Private Sub frm_chPass_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cons As String = ("data source=TONNY\SQLEXPRESS;initial catalog=APP;Persist security info=true;uid=sa;password=sally")
        conn = New SqlConnection(cons)
        conn.Open()
        da = New SqlDataAdapter("select * from tbl_user", cons)
        Dim cb As New SqlCommandBuilder(da)
        da.Fill(dt)
        kunciobjek()
    End Sub


    Private Sub Btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.BindingContext(dt).EndCurrentEdit()
        da.Update(dt)



    End Sub

    Private Sub Btn_changepasword(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        bukaobjek()

    End Sub
End Class



anyone can hel me plz T__T i am still so newbie so need your help..i dunno what to do in button1(button to change pasword)
Posted
Updated 8-Sep-11 19:34pm
v4
Comments
Wendelius 9-Sep-11 0:48am    
Pre tags added

1 solution

Hello friend..

You Can do this by Two Way..

1) Using all code done in VB.NET
2) Using a Store Procedure


1)Using all code done in VB.NET
NOTE:
"all the code below is done in asp.net with vb.net you need to change as per your requirment"

VB
Imports System.Data.SqlClient
Imports System.Data

Public Class _Default
    Inherits System.Web.UI.Page
    Dim sqlCon As SqlConnection
    Dim sqlDa As SqlDataAdapter
    Dim dt As DataTable
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not IsPostBack) Then
            sqlCon = New SqlConnection("Your Connection string goes here")
        End If
    End Sub

   Protected Sub btnChangePass_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnChangePass.Click
        Dim userName As String
        Dim oldPass As String = txtOldPass.Text
        Dim newPass As String = txtNewPass.Text
        If (oldPass.Equals(newPass)) Then

            userName = "Your User Name Goes Here"
            dt = New DataTable()
            sqlCon.Open()
            sqlDa.SelectCommand = New SqlCommand("SELECT * FROM USERTABLE WHERE USERNAME = @UserName AND PASS = @Pass", sqlCon)
            sqlDa.SelectCommand.Parameters.AddWithValue("@UserName", userName)
            sqlDa.SelectCommand.Parameters.AddWithValue("@UserName", oldPass)
            dt.Clear()
            sqlDa.Fill(dt)
            If (dt.Rows.Count > 0) Then
                Dim userID As String = dt.Rows(0)("YOUR ID COLUMN").ToString()
                sqlDa.UpdateCommand = New SqlCommand("UPDATE USERTABLE SET PASS = @NewPass WHERE UserID = @UserID", sqlCon)
                sqlDa.UpdateCommand.Parameters.AddWithValue("@NewPass", newPass)
                sqlDa.UpdateCommand.Parameters.AddWithValue("@UserID", userID)
                sqlDa.UpdateCommand.ExecuteNonQuery()
            End If
        Else
            'display your password not match message to user
        End If

    End Sub
End Class



2) Using a Store Procedure


SQL
CREATE PROCEDURE SP_CHANGE_PASS
	-- Add the parameters for the stored procedure here
	@UserName nvarchar(20),
	@OldPass nvarchar(20),
	@newPass nvarchar(20),
	@ResultID int = NULL
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT @ResultID = ID FROM TestTable WHERE Name = @UserName AND pass = @OldPass
	IF(@ResultID IS NOT NULL)
	BEGIN	
		UPDATE TestTable SET pass = @newPass WHERE ID = @ResultID
	END
END
GO


For use of this sp you need to pass three parameter like user name, oldPass and new pass,
just only call that sp and it will done all your work for you of changing password.
you can also add a output parameter as result of this sp for you use in code page of vb.net
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900