hey all..i want change password code in asp.net with vb..
i wrote following code..but the thing is that the user can enter any email id or password and update it.
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Dim cn As New SqlClient.SqlConnection(cnstring)
Dim cmd As New SqlClient.SqlCommand
Dim sql As String
Dim vname, vpswd, vnew, vid As String
Try
vname = TextName.Text
vpswd = TextOPswrd.Text
vnew = TextNew.Text
vid = TextEID.Text
sql = "update Reg set Pswrd=@Pswrd where EID=@EID"
cn.Open()
cmd.CommandType = CommandType.Text
cmd.CommandText = sql
cmd.Connection = cn
cmd.Parameters.AddWithValue("@EID", vid)
cmd.Parameters.AddWithValue("@Pswrd", vnew)
cmd.ExecuteNonQuery()
Literal1.Text = "Your password has been changed successfully"
cn.Close()
Catch ex As Exception
Literal1.Text = ex.ToString
End Try
End Sub
Loading
Satyapriya NayakPosted Apr 1, 2012, 3:26 AM
Try this...
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="Change_password_in_asp._Default" %>
Imports System.Data
Imports System.Data.SqlClient
Partial Public Class _Default
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Dim str As String
Dim com As SqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
Dim up As Byte
Protected Sub btn_cpass_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_cpass.Click
Try
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Open()
str = "select * from emp"
com = New SqlCommand(str, con)
Dim reader As SqlDataReader = com.ExecuteReader
Do While reader.Read
If txtpassword.Text = reader("oldpwd") Then
up = 1
End If
Loop
reader.Close()
con.Close()
If up = 1 Then
con.Open()
str = "update emp set oldpwd='" & txtcpassword.Text & "' where oldpwd='" & txtpassword.Text & "'"
com = New SqlCommand(str, con)
com.ExecuteNonQuery()
con.Close()
Response.Write("Password changed")
Else
Response.Write("Please enter correct Oldpassword")
txtpassword.Focus()
End If
Catch ex As Exception
Response.Write(ex.Message)
End Try
clear()
bindgrid()
End Sub
Protected Sub btn_clear_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_clear.Click
clear()
End Sub
Sub clear()
txtpassword.Text = ""
txtnpassword.Text = ""
txtcpassword.Text = ""
txtpassword.Focus()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
bindgrid()
End If
End Sub
Sub bindgrid()
con.Open()
str = "select * from emp"
com = New SqlCommand(str, con)
sqlda = New SqlDataAdapter(com)
ds = New DataSet()
sqlda.Fill(ds, "emp")
GridView1.DataSource = ds
GridView1.DataMember = "emp"
GridView1.DataBind()
con.Close()
End Sub
End Class
Thanks
If this post helps you mark it as answer