•  runboy
  • 77% (Friendly)
  • YAF Lover Topic Starter
I am in the process of converting some CS forums to YAF and in the process ended up with a lot of clear text passwords in the database. Just wanted to share how I went about changing all the passwords to hashed passwords. Hope it will help somebody one day:

using System;
using System.Web.Security;
using System.Data;
using System.Data.SqlClient;

// Set enablePasswordReset="true" in spNetSqlMembershipProvider in web.config

public partial class Hash : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        string connectionString = "Data Source=(local);Initial Catalog=YAFDB;Integrated Security=True";
        SqlConnection MEMconn = new SqlConnection(connectionString);
        string sql = "SELECT username, Password FROM yaf_prov_Membership WHERE PasswordFormat = 0";
        SqlCommand selectCMD = new SqlCommand(sql, MEMconn);
        SqlDataAdapter yafDA = new SqlDataAdapter();
        yafDA.SelectCommand = selectCMD;
        DataSet yafDS = new DataSet();
        yafDA.Fill(yafDS, "yaf_prov_Membership");
        var hashedProvider = Membership.Providers["YafMembershipProvider"];
        foreach (DataRow yafRow in yafDS.Tables["yaf_prov_Membership"].Rows)
                var resetPassword = hashedProvider.ResetPassword(yafRow["username"].ToString(), null);
                hashedProvider.ChangePassword(yafRow["username"].ToString(), resetPassword, yafRow["password"].ToString());    
        Response.Write("Operation Complete");

Users browsing this topic

    About Us

    The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

    Powered by Resharper Donate with PayPal button

    Project Twitter Updates

    Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved