63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.SharePoint;
|
|
using Taloyhtio.SSOExtension.CodeFiles;
|
|
|
|
namespace EncryptPasswords
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
if (args.Length != 1)
|
|
{
|
|
Console.WriteLine("Usage: .exe <web_app_url>");
|
|
return;
|
|
}
|
|
|
|
using (var site = new SPSite(args[0]))
|
|
{
|
|
var web = site.WebApplication.Sites[0].RootWeb;
|
|
var list = web.Lists.Cast<SPList>().FirstOrDefault(l => l.Title == Constants.CACHED_CREDENTIALS_LIST);
|
|
if (list == null)
|
|
{
|
|
log("Cached credentials list not found");
|
|
return;
|
|
}
|
|
|
|
foreach (SPListItem item in list.Items)
|
|
{
|
|
if ((string) item["FSObjType"] == "0")
|
|
{
|
|
//log("User: '{0}'; pwd: '{1}'", item[Constants.FIELD_USER_NAME], item[Constants.FIELD_PASSWORD]);
|
|
log("Decrypt password for user: '{0}'", item[Constants.FIELD_USER_NAME]);
|
|
string password = item[Constants.FIELD_PASSWORD] as string;
|
|
if (string.IsNullOrEmpty(password))
|
|
{
|
|
log("\tCan't decrypt password: password is empty");
|
|
continue;
|
|
}
|
|
item[Constants.FIELD_PASSWORD] = CredentialsCryptographer.Encrypt(password);
|
|
item.Update();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void log(string msg, params object[] args)
|
|
{
|
|
try
|
|
{
|
|
msg = string.Format(msg, args);
|
|
msg = string.Format("{0}\t{1}\n", DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"), msg);
|
|
File.AppendAllText("c://temp/_ssoextension_encryptpasswords.txt", msg);
|
|
}
|
|
catch { }
|
|
}
|
|
}
|
|
}
|