0

I have a webform gridview. In that one columns is password. I want to allow the users to change the password. there are few issues.

In the Edit template I have mentioned the password column TextMode as Password. So it shows blank when I click on the edit button.

So when I click on the edit mode the password column should display the password mask characters '*' and if the user changes the password it should be updated on the database.

I am using the SHA1 encryption for the password so I think I can retrive the password value from the db and keep it on the frontpage won't be any security issue.

Saanch
  • 1,814
  • 1
  • 24
  • 38

2 Answers2

1

Finally I found a solution for this issue with jQuery.
May be useful to someone.

        <asp:TemplateField HeaderText="Password">
            <EditItemTemplate> 
                <asp:TextBox ID="txtPassword" runat="server" Width="98%"
                    TextMode="Password" MaxLength="50" Text='<%# Bind("UserPassword") %>' CssClass="blankPassword"></asp:TextBox>
                <asp:RequiredFieldValidator ID="rfvPassword" runat="server" ErrorMessage="Required"
                    Display="Dynamic" ControlToValidate="txtPassword" ValidationGroup="Saving" CssClass="RequiredValidationMessage"></asp:RequiredFieldValidator>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="lblPassword" runat="server" Text='*****'></asp:Label>
            </ItemTemplate>
            <FooterTemplate>
                    <asp:TextBox ID="txtNewPassword" runat="server" Text='<%# Bind("UserPassword") %>' Width="95%"
                        TextMode="Password" MaxLength="50"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="rfvNewPassword" runat="server" ErrorMessage="Required"
                        Display="Dynamic" ControlToValidate="txtNewPassword" ValidationGroup="Adding" CssClass="RequiredValidationMessage"></asp:RequiredFieldValidator>
            </FooterTemplate>
            <ItemStyle Width="30%" />
        </asp:TemplateField>       


<script type="text/javascript" language="javascript" charset="utf-8">
        $(document).ready(function() {

            $(function() {
                $("input[id$='txtPassword']").live("click", function() {
                $tb = $(this);
                    $("#PasswordEdited").val("true");
                    $tb.val("");                        
                })
            });
            $(function() {
                $(".blankPassword").each(function() {
                    $tb = $(this);
                    $tb.val('*****');
                    $tb.removeClass("blankPassword");
                })
            });
        });
</script>
Saanch
  • 1,814
  • 1
  • 24
  • 38
0

TextBox inside EditItemTemplate.Then try to add the value attribute to TextBox like below.

<asp:TextBox ID="txtNewPassword" runat="server" Text='<%# Bind("UserPassword") %>' Value='<%# Bind("UserPassword") %>' Width="95%" TextMode="Password" MaxLength="50"></asp:TextBox>

Hope This Work !!!!

Dhiren Patel
  • 630
  • 8
  • 16