I suggest everyone to stretch their brains after the weekend and start the work week with simple at first glance, C # programming tasks. Perhaps these tasks will force you to look at the code of your projects from a new perspective, since they all relate to the gloomy area - the area of application security, Application Security. Not much is written about AppSec and the .NET platform, they say even less, some generally believe that using any managed language magically makes the application protected. I try to correct this state of affairs by telling at conferences about various aspects of the security of the .NET platform. So this week, on Thursday, our SPB .NET Community is holding a mitap in St. Petersburg entirely dedicated to the development of secure ASP .NET applications . Who cares about the details of this meeting, who wants to learn more about the .NET community of St. Petersburg developers and try their hand at solving the tasks on AppSec .NET, I invite you to the cat!<%@ Page Language="C#" AutoEventWireup="true"%> <script language="C#" runat="server"> protected void Page_Load(object sender, EventArgs e) { var text = TextBox1.Text + TextBox2.Text; if (text != String.Empty) { Label1.Text = "Input: " + text; } else { TextBox1.Text = Request["first"] + Request["second"]; } int count; if (Int32.TryParse(Request["count"], out count)) { for (int i = 0; i < count; i++) { var name = String.Format("base64_item{0}", i); var value = Request[name]; if (value != null) { RadioButtonList1.Items.Add(new ListItem(Encoding.UTF8.GetString(Convert.FromBase64String(value)), value)); } } } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> </head> <body> <!-- <asp:Label runat="server"> <%= Request["first"] + Request["second"] %> </asp:Label> --> Preview: <img src="<%= ResolveUrl("~/Content/Images/" + Request["page"] + ".png")%>"/> <form id="form1" runat="server"> <asp:Label ID="Label1" runat="server"></asp:Label><br/> <asp:RadioButtonList ID="RadioButtonList1" runat="server"/><br/> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br/> <asp:Button ID="Button1" runat="server" Text="Save"/> </form> </body> </html> protected void Page_Load(object sender, EventArgs e) { using (var db = new CoinsDB()) { var where = String.Empty; var parameters = new List<object>(); var email = Request["email"]; if (email != null) { where += String.Format(" email LIKE '{0}%'", email); } var field = Request["field"]; var min = Request["min"]; var max = Request["max"]; if (field != null && min != null && max != null) { if (!String.IsNullOrEmpty(where)) { where += " AND"; } where += String.Format(" {0} >= @min AND {0} <= @max", EncodeSqlField(field)); parameters.Add(new SqlParameter("@min", min)); parameters.Add(new SqlParameter("@max", max)); } var query = "SELECT * FROM CustomerLogin"; if (!String.IsNullOrEmpty(where)) { query += " WHERE"; query += where; } var output = db.Database.SqlQuery<CustomerLogin>(query, parameters.ToArray()).ToArray(); lblOutput.Text = output.Length == 0 ? "Not found" : String.Join("<br/>", output.Select(customer => customer.login + " - " + customer.rating)); } } private string EncodeSqlField(string field) { return field.Replace("'", String.Empty) .Replace(" ", String.Empty) .Replace("\\", String.Empty) .Replace(",", String.Empty) .Replace("(", String.Empty) .Replace(")", String.Empty); } [Table("CustomerLogin")] public partial class CustomerLogin { [Key] [StringLength(100)] public string login { get; set; } [StringLength(100)] public string email { get; set; } public long raiting { get; set; } public long customerNumber { get; set; } [Required] [StringLength(40)] public string password { get; set; } public short? question_id { get; set; } [StringLength(50)] public string answer { get; set; } } Source: https://habr.com/ru/post/260875/
All Articles