0% found this document useful (0 votes)
83 views10 pages

73 - Special Task List

The document contains code for three programs: 1. A program to import data from an Excel file into a database table by allowing users to upload an Excel file and read the data to store it in a database. 2. A program to implement a user registration page that restricts passwords based on a configurable password policy with requirements for numbers of lowercase, uppercase, numeric, and special characters. 3. A program to allow users to log in with a Google Authenticator one-time password (OTP) code by integrating Google authentication.

Uploaded by

divyarajc073
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views10 pages

73 - Special Task List

The document contains code for three programs: 1. A program to import data from an Excel file into a database table by allowing users to upload an Excel file and read the data to store it in a database. 2. A program to implement a user registration page that restricts passwords based on a configurable password policy with requirements for numbers of lowercase, uppercase, numeric, and special characters. 3. A program to allow users to log in with a Google Authenticator one-time password (OTP) code by integrating Google authentication.

Uploaded by

divyarajc073
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Special-Task

Name: Divyarajsinh Chudasama


Eno: 92100133073

Special exercises :

1. Write a program to allow user to upload Excel file and read data from excel and store it
into database, columns are as follows.

EmployeeName ContactNumer Address Gender Education

Note : Required tables to be created with your wisdom.

using System;

using System.Collections.Generic;

using System.Data.Entity;

using System.IO;

using System.Linq;

using System.Threading.Tasks;

using System.Web;

using System.Web.Mvc;

using Excel_final.Models;

using Microsoft.AspNetCore.Http;

using OfficeOpenXml;

namespace Excel_final.Controllers

public class HomeController : Controller

public ActionResult Index()

{
return View();

public async Task<ActionResult> Import(IFormFile file)

private excel dbContext;

var list =new List<Employees>();

using(var stream=new MemoryStream())

await file.CopyToAsync(stream);

using (var package = new ExcelPackage(stream)) {

ExcelWorksheet worksheet = package.Workbook.Worksheets[0] ;

var rowcount=worksheet.Dimension.Rows;

for(int row=2;row<=rowcount;row++)

list.Add(new Employees {

EmployeeID = worksheet.Cells[row,1].Value.ToString().Trim(),

Name= worksheet.Cells[row, 2].Value.ToString().Trim(),

Address= worksheet.Cells[row, 3].Value.ToString().Trim(),

phnumber= worksheet.Cells[row, 4].Value.ToString().Trim(),

Gender= worksheet.Cells[row, 5].Value.ToString().Trim(),

Education= worksheet.Cells[row, 6].Value.ToString().Trim()

});

dbContext.Employees.AddRange(list);

dbContext.SaveChanges();

return RedirectToAction("Index");

public ActionResult About()


{

ViewBag.Message = "Your application description page.";

return View();

public ActionResult Contact()

ViewBag.Message = "Your contact page.";

return View();

Model

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

namespace Excel_final.Models

public class Employees

public String EmployeeID { get; set; }

public String Name { get; set; }

public String phnumber { get; set;}

public String Address { get; set; }

public String Gender{ get; set; }

public String Education { get; set; }

}
}

View

@{

ViewBag.Title = "Home Page";

<div class="myCarosel" class ="carousel slide" data-ride="carousel" data-interval="6000">

<div class="container">

<form method="post" asp-controller="Home" asp-action="Import"


enctype="multipart/form-data">

<input type="file" / name="file">

<button type="submit">Import from excel</button>

</form>

</div>

</div>

2. Write a program which has 2 pages as follows :

A) Page for User Password policy configuration

B) User registration page with password policy restriction

I.e. 2 lowercase, 1 upercase, 1 numeric, 2 special character etc where number should be
choose by user.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page

protected void Page_Load(object sender, EventArgs e)

{
// You can retrieve the password policy configuration from a database or a
configuration file

// For simplicity, we'll hardcode a sample policy here

int lowercaseCount = 2; // Example: 2 lowercase characters required

int uppercaseCount = 1; // Example: 1 uppercase character required

int numericCount = 1; // Example: 1 numeric character required

int specialCount = 2; // Example: 2 special characters required

lblPasswordPolicy.Text = $"Password Policy: {lowercaseCount} lowercase,


{uppercaseCount} uppercase, {numericCount} numeric, {specialCount} special characters";

protected void btnRegister_Click(object sender, EventArgs e)

string password = txtPassword.Text;

int lowercaseCount = 2;

int uppercaseCount = 1;

int numericCount = 1;

int specialCount = 2;

string lowercaseRegex = "[a-z]{" + lowercaseCount + ",}";

string uppercaseRegex = "[A-Z]{" + uppercaseCount + ",}";

string numericRegex = "\\d{" + numericCount + ",}";

string specialRegex = "[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>/?~]{" + specialCount +


",}";

if (System.Text.RegularExpressions.Regex.IsMatch(password, lowercaseRegex) &&

System.Text.RegularExpressions.Regex.IsMatch(password, uppercaseRegex) &&

System.Text.RegularExpressions.Regex.IsMatch(password, numericRegex) &&

System.Text.RegularExpressions.Regex.IsMatch(password, specialRegex))

Response.Write("User registered successfully.");

}
else

Response.Write("Password does not meet the policy requirements.");

View

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserRegistration.aspx.cs"


Inherits="YourNamespace.UserRegistration" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>User Registration</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<h1>User Registration</h1>

<asp:Label ID="lblPasswordPolicy" runat="server" ForeColor="Red"></asp:Label>

<div>

Username: <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>

</div>

<div>

Password: <asp:TextBox ID="txtPassword" runat="server"


TextMode="Password"></asp:TextBox>

</div>

<div>

<asp:Button ID="btnRegister" runat="server" Text="Register"


OnClick="btnRegister_Click" />

</div>

</div>
</form>

</body>

</html>

PasswordRegex.aspx

<%@ Page Language="C#" AutoEventWireup="true"


CodeBehind="PasswordPolicyConfiguration.aspx.cs"
Inherits="YourNamespace.PasswordPolicyConfiguration" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Password Policy Configuration</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<h1>Password Policy Configuration</h1>

<asp:Label ID="lblMessage" runat="server" ForeColor="Red"


Visible="false"></asp:Label>

<div>

Number of Lowercase Characters: <asp:TextBox ID=" "


runat="server"></asp:TextBox>

</div>

<div>

Number of Uppercase Characters: <asp:TextBox ID="txtUppercase"


runat="server"></asp:TextBox>

</div>

<div>

Number of Numeric Characters: <asp:TextBox ID="txtNumeric"


runat="server"></asp:TextBox>

</div>

<div>
Number of Special Characters: <asp:TextBox ID="txtSpecial"
runat="server"></asp:TextBox>

</div>

<div>

<asp:Button ID="btnSubmit" runat="server" Text="Save"


OnClick="btnSubmit_Click" />

</div>

</div>

</form>

</body>

</html>

PasswordRegex.aspx.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class PasswordRegex : System.Web.UI.Page

protected void btnSubmit_Click(object sender, EventArgs e)

int lowercaseCount = int.Parse(txtLowercase.Text);

int uppercaseCount = int.Parse(txtUppercase.Text);

int numericCount = int.Parse(txtNumeric.Text);

int specialCount = int.Parse(txtSpecial.Text);

lblMessage.Text = "Password policy configuration saved!";

lblMessage.Visible = true;

}
3. Write a program to allow user to login with Google authenticator OTP code.

using FluentAssertions.Common;

using Microsoft.AspNetCore.Identity;

using Microsoft.EntityFrameworkCore;

using WebApplication1.Data;

var connectionString =
builder.Configuration.GetConnectionString("WebApplication1ContextConnection") ?? throw new
InvalidOperationException("Connection string 'WebApplication1ContextConnection' not found.");

builder.Services.AddDbContext<WebApplication1Context>(options =>
options.UseSqlServer(connectionString));

builder.Services.AddDefaultIdentity<IdentityUser>(options =>
options.SignIn.RequireConfirmedAccount =
true).AddEntityFrameworkStores<WebApplication1Context>();

var configuration = builder.Configuration;

builder.Services.AddAuthentication().AddGoogle(googleOptions =>

googleOptions.ClientId = configuration["Authcd enticaation:Google:ClientId"];

googleOptions.ClientSecret = configuration["Authenticaation:Google:ClientSecret"];

});

builder.Services.AddControllersWithViews();

var app = builder.Build();

// Configure the HTTP request pipeline.

if (!app.Environment.IsDevelopment())

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

// The default HSTS value is 30 days. You may want to change this for production scenarios, see
https://aka.ms/aspnetcore-hsts.

app.UseHsts();

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(

name: "default",

pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run()

You might also like