Differences between MD5 and SHA1

 

MD5

SHA1

MD5 stands for Message Digest.

While SHA1 stands for Secure Hash Algorithm.

MD5 can have 128 bits length of message digest.

Whereas SHA1 can have 160 bits length of message digest.

The speed of MD5 is fast in comparison of SHA1’s speed.

While the speed of SHA1 is slow in comparison of MD5’s speed.

To make out the initial message the aggressor would want 2^128 operations whereas exploitation the MD5 algorithmic program.

On the opposite hand, in SHA1 it’ll be 2^160 that makes it quite troublesome to seek out.

MD5 is simple than SHA1.

While SHA1 is more complex than MD5.

MD5 provides indigent or poor security.

While it provides balanced or tolerable security.

In MD5, if the assailant needs to seek out the 2 messages having identical message digest then assailant would need to perform 2^64 operations.

Whereas in SHA1, assailant would need to perform 2^80 operations which is greater than MD5.

MD5 was presented in the year 1992.

While SHA1 was presented in the year 1995.

 

Code Refactoring in C#

Code refactoring allows you to change the code structure without changing or affecting what the code itself actually does. Code refactoring is the practice of taking previously written code and rewriting it to make it more efficient.


Using code refactorings:

On a symbol in the text editor.

On a code selection in the text editor.

On a file or a selection of files in the Solution Explorer tool window.

On a type member or a selection of type members in File Structure or another ReSharper tool window.


Change Signature

This refactoring allows you to modify a method signature in the following ways:

Add, remove, rename, or reorder parameter(s)

Change return type

Change parameter type(s)

Rename method


Refactoring can be explained as the process of improving your code after it has been written by changing:

The internal structure of the code.

External behavior of the code.


Methods

There are 5 methods of applying effective refactoring over your code, these methods are already available in Visual studio:

Extract Method

Extract interface

Rename

Promote variable to the parameter

Encapsulate Field

Generate method stub

Multiple inheritance using interfaces




C# does not support multiple class inheritance. To overcome this problem we use interfaces to achieve multiple class inheritance. With the help of the interface, class C( as shown in the above diagram) can get the features of class A and B.

ACID Properties in DBMS

Atomicity:

By this, we mean that either the entire transaction takes place at once or doesn’t happen at all. There is no midway i.e. transactions do not occur partially. Each transaction is considered as one unit and either runs to completion or is not executed at all. It involves the following two operations. 

—Abort: If a transaction aborts, changes made to the database are not visible. 

—Commit: If a transaction commits, changes made are visible. 

Atomicity is also known as the ‘All or nothing rule’. 

Consistency:

This means that integrity constraints must be maintained so that the database is consistent before and after the transaction. It refers to the correctness of a database.

Isolation:

This property ensures that multiple transactions can occur concurrently without leading to the inconsistency of the database state. Transactions occur independently without interference. Changes occurring in a particular transaction will not be visible to any other transaction until that particular change in that transaction is written to memory or has been committed. This property ensures that the execution of transactions concurrently will result in a state that is equivalent to a state achieved these were executed serially in some order. 

Durability: 

This property ensures that once the transaction has completed execution, the updates and modifications to the database are stored in and written to disk and they persist even if a system failure occurs. These updates now become permanent and are stored in non-volatile memory. The effects of the transaction, thus, are never lost. 

Setting session in Asp.Net Core 7.0 MVC project

I am using Visual Studio 2022

To Set the session in Asp.Net Core 7.0 MVC project, do the following changes :- ___________________________________________________________________________________

In Program.cs file:-


using Microsoft.AspNetCore.Builder;

using Microsoft.AspNetCore.Hosting;

using Microsoft.AspNetCore.Razor.Language.Intermediate;


var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllersWithViews();

builder.Services.AddSession();

var app = builder.Build();

if (!app.Environment.IsDevelopment())

{

    app.UseExceptionHandler("/Home/Error");

    app.UseHsts();

}

app.UseSession();

app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(

name: "default",

pattern: "{controller=HR}/{action=HRLogin}/{id?}");

app.Run();
____________________________________________

In Controller:-

HttpContext.Session.SetString("username", login.Username.ToString());

then call the session value

string SessionName = HttpContext.Session.GetString("username");

Cross-Origin Requests (CORS) in ASP.NET Core

CORS is a security feature that prevents malicious websites from making unauthorized requests to a different domain. ASP.NET Core provides an easy way to configure CORS for web applications by using the Microsoft.AspNetCore.Cors package. Developers can enable CORS for all origins, headers, and methods or configure CORS to only allow specific origins, headers, and methods.

An example of a CORS rules:
app.UseCors(builder =>
        builder
        .WithOrigins("http://domain.com")
        .AllowAnyMethod()
        .AllowAnyHeader());

To enable CORS in ASP.Net Core Web API, these are the steps we need to follow :-
- Install the CORS middleware.
- Register CORS middleware to the pipeline in the ConfigureServices method of Startup.cs.
- Enable CORS in the Configure method of Startup.cs.
- Enable/Disable CORS in the controllers, the action methods, or globally.

How to Find Nth Highest Salary in SQL

 SELECT * FROM(

SELECT emp_name, salary, DENSE_RANK() 

over(ORDER BY salary DESC) AS ranking FROM employee) AS k

WHERE ranking=2;



SELECT * FROM(

SELECT emp_name, salary, ROW_NUMBER() 

over(ORDER BY salary DESC) AS ranking FROM employee) AS k

WHERE ranking=2;



SELECT * FROM(

SELECT emp_name, salary, RANK() 

over(ORDER BY salary DESC) AS ranking FROM employee) AS k

WHERE ranking=2;


Web API vs Rest API

 1) Web API vs REST API: Protocol

Web API supports protocol for HTTP/s protocol and URL requests/responses headers that enable services to reach various clients through the web. On the other hand, all communication in the REST API is supported only through HTTP protocol.


2) Web API vs REST API: Formats

Although APIs perform identical tasks, a Web API provides flexibility to any style of communication. Whereas a REST API can take advantage of using REST, SOAP, and XML-RPC for communication.


3) Web API vs REST API: Design

As Web APIs are lightweight architecture, they are designed for gadgets constrained to devices like smartphones. In contrast, REST APIs send and receive data over systems making it a complex architecture.


4) Web API vs REST API: Support

Web API can be hosted only on an Internet Information Service (IIS) or self that supports XML and JSON requests. In contrast, REST API can be hosted only on IIS that supports standardized XML requests.

Difference Between Code First Approach And Database First Approach

 Code First Approach

In code first approach, we will first create entity classes with properties defined in it. Entity framework will create the database and tables based on the entity classes defined. So database is generated from the code. When the dot net code is run database will get created.

Advantages

1.      You can create  the database and tables from your business objects.

2.      You can specify which related collections are to be eager loaded or not be serialized at all.

3.      Database version control.

4.      Good for small applications.

Disadvantages

1.      You have to write everything related to database in the visual studio code.

2.      For stored procedures you have to map stored procedure using Fluent API and write Stored Procedure inside the code.

3.      If you want to change anything in the database tables you to make changes in the entity classes in the code file and run the update-database from the  package manager console.

4.      Not preferred for Data intensive applications. 


Database First Approach

In this approach Database and tables are created first. Then you create entity Data Model using the created database.

Advantages

1.      Simple to create the data model

2.      Graphical  user interface.

3.      Mapping and creation of keys and relationships are easy as you need not have to write any code .

4.      Preferred for data intense and large applications

Disadvantages

1.      Using an existing database to generate a .edmx model file and the associated code models results in a giant pile of auto generated code.

2.      When you need to add any functionality to generated model you have to extend the model class generated.