Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added BaiTap/Login.rar
Binary file not shown.
27 changes: 27 additions & 0 deletions BaiTap/Login/dashbord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
session_start();
if ($_SESSION["Login"] == false)
header("location: login.html");

if($_SERVER["REQUEST_METHOD"] == "POST"){
$_SESSION["Login"] = false;
header("location: login.html");
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>Đã đăng nhập thành công</h2>
<form action="dashbord.php" method="post">
<button class="logoutBtn" type="submit">Log out</button>
</form>


</body>
</html>
74 changes: 74 additions & 0 deletions BaiTap/Login/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Login</title>
<!-- <link rel="stylesheet" type="text/css" href="style.css" /> -->
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh; /* chiều cao của toàn màn hình */
background-color: #f4f4f4;
}

.container {
width: 300px;
background: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;
color: #333;
}

label {
font-weight: bold;
}

input[type="text"],
input[type="password"],
input[type="submit"] {
width: 100%;
padding: 10px;
margin: 8px 0;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}

input[type="submit"] {
background-color: #4caf50;
color: white;
border: none;
cursor: pointer;
}

input[type="submit"]:hover {
background-color: #45a049;
}

.error-msg {
color: red;
text-align: center;
}
</style>
</head>
<body>
<form action="validate.php" method="POST">
<label for="username">Username:</label>
<input type="text" id="username" name="username" /><br /><br />
<label for="password">Password:</label>
<input type="password" id="password" name="password" /><br /><br />
<input type="submit" name="Login" value="Login" /><br /><br />
</form>
<form>
<button><a href="register.html">Register</a></button>
</form>
</body>
</html>
9 changes: 9 additions & 0 deletions BaiTap/Login/logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
session_start();

// Reset trạng thái login
$_SESSION["IsLogin"] = false;

// Redirect về trang login
header("Location: login.html");
?>
25 changes: 25 additions & 0 deletions BaiTap/Login/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Register</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<h2>Register</h2>
<form action="register.php" method="post">
<input type="text" name="username" placeholder="Username" required />
<input type="email" name="email" placeholder="Email" required />
<input
type="password"
name="password"
placeholder="Password"
required
/>
<button type="submit">Register</button>
</form>
</div>
</body>
</html>
36 changes: 36 additions & 0 deletions BaiTap/Login/register.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
// Kết nối đến cơ sở dữ liệu
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydb";

$conn = new mysqli($servername, $username, $password, $dbname);

// Kiểm tra kết nối
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Lấy dữ liệu từ form đăng ký
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];

// Mã hóa mật khẩu
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

// Thêm dữ liệu vào cơ sở dữ liệu
$sql = "INSERT INTO tbllogin2 (username, pass, email) VALUES ('$username', '$hashed_password', '$email')";

if ($conn->query($sql) === TRUE) {
// Đăng ký thành công, chuyển hướng về trang đăng nhập và hiển thị thông báo
echo "<script>alert('Registered successfully'); window.location='login.html';</script>";

} else {
// Nếu có lỗi, hiển thị thông báo lỗi
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>
77 changes: 77 additions & 0 deletions BaiTap/Login/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}

.container {
width: 300px;
margin: 0 auto;
margin-top: 100px;
background: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;
color: #333;
}

label {
font-weight: bold;
}

input[type="text"],
input[type="password"],
input[type="submit"] {
width: 100%;
padding: 10px;
margin: 8px 0;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}

input[type="submit"] {
background-color: #4caf50;
color: white;
border: none;
cursor: pointer;
}

input[type="submit"]:hover {
background-color: #45a049;
}

.error-msg {
color: red;
text-align: center;
}

.container {
width: 50%;
margin: 0 auto;
text-align: center;
}

input[type="text"],
input[type="email"],
input[type="password"],
button {
margin: 10px 0;
padding: 10px;
width: 100%;
border: 1px solid #ccc;
border-radius: 5px;
}

button {
background-color: #4caf50;
color: white;
cursor: pointer;
}

button:hover {
background-color: #45a049;
}
50 changes: 50 additions & 0 deletions BaiTap/Login/validate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
session_start();
ob_start();
// Kết nối đến CSDL
$servername = "localhost";
$username = "root"; // Thay bằng username của bạn
$password = ""; // Thay bằng password của bạn
$dbname = "mydb"; // Thay bằng tên CSDL của bạn

$conn = new mysqli($servername, $username, $password, $dbname);

// Kiểm tra kết nối
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Lấy thông tin từ form đăng nhập
$username = $_POST['username'];
$password = $_POST['password'];

// Mã hóa mật khẩu bằng sha1()
$hashed_password = password_hash($password, PASSWORD_DEFAULT);

// Xử lí thông tin đăng nhập
$sql = "SELECT * FROM tbllogin2 WHERE username='$username'";
$result = $conn->query($sql);
// $txt_error = "Username và password không hợp lệ";
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();

// So sánh mật khẩu đã mã hóa
$hashed_password = $row['pass'];
if (password_verify($password, $hashed_password)) {
// Đăng nhập thành công, lưu trạng thái vào Session
$_SESSION["Login"] = true;
header("location: dashbord.php"); // Chuyển hướng đến trang dashboard sau khi đăng nhập thành công
} else {
// Mật khẩu không đúng
echo "<script>alert('Sai mật khẩu'); window.location='login.html?error=invalid_credentials';</script>";
}
} else {
// Tài khoản không tồn tại
echo "<script>alert('Tài khoản không tồn tại'); window.location='login.html';</script>";

}


$conn->close();

?>
Empty file added BaiTap/ProjectCuoiKi/App.scss
Empty file.
12 changes: 12 additions & 0 deletions BaiTap/ProjectCuoiKi/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>

</body>
</html>
Empty file added BaiTap/ProjectCuoiKi/script.js
Empty file.
Empty file.
Binary file added BaiTap/Week2/database.db
Binary file not shown.
57 changes: 57 additions & 0 deletions BaiTap/Week2/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bảng Sinh Viên</title>
<link rel="stylesheet" href="style.css">
</head>
<body>

<table class="student-table">
<thead>
<tr>
<th>MSSV</th>
<th>Họ và Tên</th>
<th>Kỳ</th>
<th>Đăng Ký</th>
</tr>
</thead>
<tbody>
<?php
// Thông tin kết nối MySQL
$servername = "localhost";
$username = "root";
$password = "";
$database = "mydb";

// Tạo kết nối
$conn = new mysqli($servername, $username, $password, $database);

// Kiểm tra kết nối
if ($conn->connect_error) {
die("Kết nối không thành công: " . $conn->connect_error);
}

// Truy vấn dữ liệu từ bảng sinh viên
$sql = "SELECT * FROM sinhvien";

$result = $conn->query($sql);

if ($result->num_rows > 0) {
// Hiển thị dữ liệu
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["MSSV"]. "</td><td>" . $row["HoTen"]. "</td><td>" . $row["Ky"]. "</td><td>" . $row["DangKy"]. "</td></tr>";
}
} else {
echo "0 kết quả";
}

// Đóng kết nối
$conn->close();
?>
</tbody>
</table>

</body>
</html>
Loading