:
-This email was automatically generated.
",
- DefaultBodyStyle)
+}}
This email was automatically generated.
")
.MakeReadOnly();
///
diff --git a/Utilities/Converters/SecureStringConverter.cs b/Utilities/Converters/SecureStringConverter.cs
new file mode 100644
index 00000000..8064243a
--- /dev/null
+++ b/Utilities/Converters/SecureStringConverter.cs
@@ -0,0 +1,68 @@
+#region © Copyright Web Applications (UK) Ltd, 2017. All rights reserved.
+// Copyright (c) 2017, Web Applications UK Ltd
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of Web Applications UK Ltd nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL WEB APPLICATIONS UK LTD BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#endregion
+
+using System;
+using System.ComponentModel;
+using System.Globalization;
+using System.Security;
+
+namespace WebApplications.Utilities.Converters
+{
+ ///
+ /// Type converter for the class.
+ ///
+ ///
+ public class SecureStringConverter : TypeConverter
+ {
+ /// Returns whether this converter can convert an object of the given type to the type of this converter, using the specified context.
+ /// true if this converter can perform the conversion; otherwise, false.
+ /// An that provides a format context.
+ /// A that represents the type you want to convert from.
+ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
+ {
+ return sourceType == typeof(string);
+ }
+
+ /// Converts the given object to the type of this converter, using the specified context and culture information.
+ /// An that represents the converted value.
+ /// An that provides a format context.
+ /// The to use as the current culture.
+ /// The to convert.
+ /// The conversion cannot be performed.
+ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
+ {
+ if (!(value is string str)) return base.ConvertFrom(context, culture, value);
+
+ SecureString ss = new SecureString();
+ foreach (char ch in str)
+ ss.AppendChar(ch);
+ ss.MakeReadOnly();
+
+ return ss;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Utilities/ModuleInitializer.cs b/Utilities/ModuleInitializer.cs
index a93327c9..01166d42 100644
--- a/Utilities/ModuleInitializer.cs
+++ b/Utilities/ModuleInitializer.cs
@@ -28,6 +28,7 @@
using NodaTime;
using System.ComponentModel;
using System.Net.Mail;
+using System.Security;
using System.Xml.Linq;
using WebApplications.Utilities.Annotations;
using WebApplications.Utilities.Converters;
@@ -61,6 +62,7 @@ internal static void Initialize()
TypeDescriptor.AddAttributes(typeof(XNamespace), new TypeConverterAttribute(typeof(XNamespaceConverter)));
TypeDescriptor.AddAttributes(typeof(MailAddress), new TypeConverterAttribute(typeof(MailAddressConverter)));
TypeDescriptor.AddAttributes(typeof(MailAddressCollection), new TypeConverterAttribute(typeof(MailAddressCollectionConverter)));
+ TypeDescriptor.AddAttributes(typeof(SecureString), new TypeConverterAttribute(typeof(SecureStringConverter)));
}
}
}
\ No newline at end of file
diff --git a/Utilities/WebApplications.Utilities.csproj b/Utilities/WebApplications.Utilities.csproj
index 6f12024f..ab0c8153 100644
--- a/Utilities/WebApplications.Utilities.csproj
+++ b/Utilities/WebApplications.Utilities.csproj
@@ -61,6 +61,7 @@
+