Wednesday, February 18, 2015

simple change password code in vb.net

Posted by Gnani Palepu  |  No comments


 simple change password code in vb.net  
 -----------------------------------------  
 step 1  
 -------  
 html:  
     <div class="forgotb">  
       <a href="javascript:void(0)" onclick="checkusernameandpwd()">Change Password</a>  
     </div>  
     <div id="light" class="white_content" runat="server">  
       <div style="float: left; width: 100%;">  
         <a style="float: right;" href="javascript:void(0)" onclick="closepopup();">Close</a>  
         <table width="100%;">  
           <tr>  
             <td style="height: 45px; width: 30%;">  
               User Name  
             </td>  
             <td style="height: 45px; width: 30%;">  
               <asp:TextBox ID="txtUserCode" runat="server" placeholder="User Code" Style="width: 270px;" />  
             </td>  
             <td style="height: 45px; width: 40%;">  
               <asp:RequiredFieldValidator ID="UserNameRequired" ErrorMessage="User Name is Required" ForeColor="Red"  
                 ControlToValidate="txtUserCode" runat="server" ValidationGroup="popupbtnval" />  
             </td>  
           </tr>  
           <tr>  
             <td style="height: 45px;">  
               Current Password  
             </td>  
             <td style="height: 45px;">  
               <asp:TextBox ID="txtCurrentPassword" runat="server" placeholder="Current Password"  
                 Style="width: 270px;" />  
             </td>  
             <td>  
               <asp:RequiredFieldValidator ID="CurrentPasswordRequired" ErrorMessage="Current Password is Required"  
                 ForeColor="Red" ControlToValidate="txtCurrentPassword" runat="server" ValidationGroup="popupbtnval" />  
             </td>  
           </tr>  
           <tr>  
             <td style="height: 45px;">  
               New Password  
             </td>  
             <td style="height: 45px;">  
               <asp:TextBox ID="passwordTextBox" runat="server" placeholder="New Password" TextMode="Password"  
                 Style="width: 270px;" />  
             </td>  
             <td>  
               <asp:RequiredFieldValidator ID="passwordReq" ErrorMessage="New Password is required!"  
                 ForeColor="Red" ControlToValidate="passwordTextBox" runat="server" ValidationGroup="popupbtnval" />  
             </td>  
           </tr>  
           <tr>  
             <td style="height: 45px;">  
               Confirm Password  
             </td>  
             <td style="height: 45px;">  
               <asp:TextBox ID="confirmPasswordTextBox" runat="server" placeholder="Confirm Password"  
                 TextMode="Password" Style="width: 270px;" />  
             </td>  
             <td>  
               <asp:RequiredFieldValidator ID="confirmPasswordReq" ErrorMessage="confirmation Password is required!"  
                 ForeColor="Red" ControlToValidate="confirmPasswordTextBox" runat="server" ValidationGroup="popupbtnval" />  
               <asp:CompareValidator ID="comparePasswords" ErrorMessage="Your passwords do not match up!"  
                 ForeColor="Red" ControlToCompare="passwordTextBox" ControlToValidate="confirmPasswordTextBox"  
                 runat="server" ValidationGroup="popupbtnval" />  
             </td>  
           </tr>  
           <tr>  
             <td style="height: 60px;" colspan="2" align="right">  
               <span style="float: left">  
                 <asp:Label runat="server" ID="lblSucessmsg"></asp:Label>  
               </span>  
               <asp:Button runat="server" ID="btnSubmit" Text="Submit" ValidationGroup="popupbtnval"  
                 Style="width: 100px;" />  
             </td>  
             <td>  
             </td>  
           </tr>  
         </table>  
       </div>  
     </div>  
     <div id="fade" class="black_overlay">  
     </div>  
 step 2:  
 --------------------  
  body  
    .black_overlay{  
      display: none;  
      position: absolute;  
      top: 0%;  
      left: 0%;  
      width: 75%;  
      height: 75%;  
      background-color: black;  
      z-index:1001;  
      -moz-opacity: 0.8;  
      opacity:.80;  
      filter: alpha(opacity=80);  
 }  
 .white_content {  
      display: none;  
      position: absolute;  
      top: 25%;  
      left: 25%;  
      width: 50%;  
      height: 50%;  
      padding: 16px;  
      border: 16px solid orange;  
      background-color: white;  
      z-index:1002;  
      overflow: auto;  
 }  
 step 3:  
 --------  
 <sccript type="text/javascript">  
     function closepopup() {  
       document.getElementById('light').style.display = 'none';  
       document.getElementById('fade').style.display = 'none';  
       document.getElementById("<%=txtUserCode.ClientID %>").value = '';  
       document.getElementById("<%=txtCurrentPassword.ClientID %>").value = '';  
       document.getElementById("<%=passwordTextBox.ClientID %>").value = '';  
       document.getElementById("<%=confirmPasswordTextBox.ClientID %>").value = '';  
       document.getElementById("<%=confirmPasswordReq.ClientID %>").innerHTML = '';  
       document.getElementById("<%=comparePasswords.ClientID %>").innerHTML = '';  
       document.getElementById("<%=lblSucessmsg.ClientID %>").innerHTML = '';  
       document.getElementById("<%=txtUserName.ClientID %>").value = '';  
       document.getElementById("<%=txtPassword.ClientID %>").value = '';  
     }  
     function checkusernameandpwd() {  
       if (document.getElementById("<%=txtUserName.ClientID %>").value == '') {  
         document.getElementById("<%=btnlogin.ClientID %>").click();  
       } else if (document.getElementById("<%=txtPassword.ClientID %>").value == '') {  
         document.getElementById("<%=btnlogin.ClientID %>").click();  
       } else {  
         document.getElementById("<%=txtUserCode.ClientID %>").value = document.getElementById("<%=txtUserName.ClientID %>").value;  
         document.getElementById("<%=txtCurrentPassword.ClientID %>").value = document.getElementById("<%=txtCurrentPassword.ClientID %>").value;  
         document.getElementById('light').style.display = 'block';  
         document.getElementById('fade').style.display = 'block';  
       }  
     }  
   </script>  
 stored procedure  
 ----------------  
 USE [SMIC]  
 GO  
 /****** Object: StoredProcedure [dbo].[USP_GET_USER_LOGIN_CHANGE_PWD]  Script Date: 02/16/2015 09:21:52 ******/  
 SET ANSI_NULLS ON  
 GO  
 SET QUOTED_IDENTIFIER ON  
 GO  
 -- =============================================  
 -- Author:     Gnani  
 -- Create date: 14/02/2015  
 -- Description:     Change password  
 -- =============================================  
 --EXEC USP_GET_USER_LOGIN_CHANGE_PWD 'gnani','gopal','gopal1',0  
 ALTER PROCEDURE [dbo].[USP_GET_USER_LOGIN_CHANGE_PWD]  
      @UserCode NVARCHAR(100),  
      @Password NVARCHAR(100),  
      @NewPassword NVARCHAR(100),  
      @ResponseCode INT OUTPUT  
 AS  
 BEGIN  
      DECLARE @UserID INT =0  
      SELECT @UserID =USERID FROM MSTUSER WHERE UserCode =@UserCode and PWD = REVERSE(@Password)  
      IF (@UserID >0 )   
            BEGIN  
                Update MSTUSER SET Pwd =REVERSE(@NewPassword) WHERE UserCode =@UserCode and PWD = REVERSE(@Password)  
                SET @ResponseCode = @UserID  
            END  
      ELSE  
           BEGIN  
                SET @ResponseCode =-999  
           END            
 END  
 code  
 ---------------  
 aspx.vb file  
 Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click  
     ClearMemory()  
     Dim connection = UserBO.GetConnectionFinalString("SMICL")  
     Dim loginRequest = New LoginRequest()  
     loginRequest.ChangeUserName = txtUserCode.Text.ToString()  
     loginRequest.Changepassword = txtCurrentPassword.Text.ToString()  
     loginRequest.ChangeNewpassword = passwordTextBox.Text.ToString()  
     loginRequest.Connection = connection  
     Dim resp = UserBO.UserLoginChangePwd(loginRequest)  
     If resp.Valid Then  
       Lblerr.Text = resp.Message  
       Lblerr.ForeColor = Drawing.Color.White  
       txtUserCode.Text = Nothing  
       txtCurrentPassword.Text = Nothing  
     Else  
       Lblerr.Text = resp.Message  
       Lblerr.ForeColor = Drawing.Color.Red  
       txtUserCode.Text = Nothing  
       txtCurrentPassword.Text = Nothing  
     End If  
   End Sub  
 Bo  
 ------  
 #Region "User Login UserLoginChangePwd"  
   Public Shared Function UserLoginChangePwd(ByVal request As LoginRequest) As LoginResponse  
     Dim response = New LoginResponse()  
     response = UserDAO.UserLoginChangePwd(request)  
     If response.ResponseCode > 0 Then  
       response.Valid = True  
       response.Message = "Password has been changed successfully."  
     Else  
       response.Valid = False  
       response.Message = "Login details not valid. please re-enter."  
     End If  
     Return response  
   End Function  
 #End Region  
 DAO  
 -------  
 #Region "User Login Change Pwd"  
   Public Shared Function UserLoginChangePwd(ByVal request As LoginRequest) As LoginResponse  
     Dim conString = Utility.Decrypt(request.Connection)  
     Dim response = New LoginResponse()  
     If conString IsNot Nothing Then  
       Dim connection As OleDbConnection = New OleDbConnection()  
       Dim paramOut As OleDbParameter = New OleDbParameter()  
       Dim da As New OleDbDataAdapter()  
       Dim dt As New DataTable()  
       connection.ConnectionString = conString  
       connection.Open()  
       Dim command = New OleDbCommand()  
       command.Connection = connection  
       command.CommandType = CommandType.StoredProcedure  
       command.CommandText = StoredProcedures.USP_GET_USER_LOGIN_CHANGE_PWD  
       command.Parameters.AddWithValue(DBParameters.UserCode, request.ChangeUserName)  
       command.Parameters.AddWithValue(DBParameters.Password, request.Changepassword)  
       command.Parameters.AddWithValue(DBParameters.NewPassword, request.ChangeNewpassword)  
       paramOut = command.Parameters.Add(DBParameters.ResponseCode, OleDbType.BigInt, 10)  
       paramOut.Direction = ParameterDirection.Output  
       command.ExecuteNonQuery()  
       response.ResponseCode = paramOut.Value  
       command.Dispose()  
       connection.Close()  
     End If  
     Return response  
   End Function  
 #End Region  

2:26 AM Share:

0 comments:

Get updates in your email box
Complete the form below, and we'll send you the best coupons.

Deliver via FeedBurner
Proudly Powered by Blogger.
back to top