runboy
  •  runboy
  • 77% (Friendly)
  • YAF Lover Topic Starter
2013-09-18T03:32:53Z
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;
        MEMconn.Open();
        DataSet yafDS = new DataSet();
        yafDA.Fill(yafDS, "yaf_prov_Membership");
        MEMconn.Close();
        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");
    }
}



Sponsor
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