0% found this document useful (0 votes)
28 views

Password Field

Uploaded by

ashamisha234
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Password Field

Uploaded by

ashamisha234
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include <GL/glew.

h>
#include <GL/glx.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <cstring>
#include <string>
#include <vector>
#include <chrono>
#include <cmath>
#include <memory>

// Shader source code for transparency and blur effects


const char* vertexShaderSource = R"(
#version 330 core
layout (location = 0) in vec2 position;
layout (location = 1) in vec2 texCoords;
out vec2 TexCoords;
void main() {
gl_Position = vec4(position.x, position.y, 0.0, 1.0);
TexCoords = texCoords;
}
)";

const char* fragmentShaderSource = R"(


#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform float time;
uniform vec2 resolution;
uniform vec3 customColor;

void main() {
vec2 uv = gl_FragCoord.xy / resolution;
float alpha = 0.7 + 0.3 * sin(time + uv.x * 10.0);
vec3 color = customColor * (0.5 + 0.5 * sin(time + uv.y * 5.0));
FragColor = vec4(color, alpha * 0.8);
}
)";

class PasswordScreen {
private:
Display* display;
Window window;
GLXContext glContext;
int screen;
GLuint shaderProgram;
GLuint VAO, VBO;
std::string password;
bool isAuthenticated;
float time;

struct {
float r = 0.2f;
float g = 0.6f;
float b = 0.8f;
} themeColor;

// Animation parameters
struct {
float pulseSpeed = 1.0f;
float glowIntensity = 0.5f;
std::vector<float> particlePositions;
} animation;

public:
PasswordScreen() : password(""), isAuthenticated(false), time(0.0f) {
initX11();
initGL();
initShaders();
initBuffers();
setupAnimations();
}

~PasswordScreen() {
cleanup();
}

void run() {
XEvent event;
bool running = true;
auto lastTime = std::chrono::high_resolution_clock::now();

while (running) {
while (XPending(display)) {
XNextEvent(display, &event);
handleEvent(event);
}

auto currentTime = std::chrono::high_resolution_clock::now();


float deltaTime = std::chrono::duration<float>(currentTime -
lastTime).count();
lastTime = currentTime;

update(deltaTime);
render();
}
}

private:
void initX11() {
display = XOpenDisplay(nullptr);
if (!display) {
throw std::runtime_error("Failed to open X display");
}

screen = DefaultScreen(display);

// Set up window attributes for transparency


XVisualInfo* vi = glXChooseVisual(display, screen, nullptr);
XSetWindowAttributes swa;
swa.colormap = XCreateColormap(display, RootWindow(display, screen),
vi->visual, AllocNone);
swa.border_pixel = 0;
swa.background_pixel = 0;
swa.event_mask = KeyPressMask | ExposureMask;

// Create main window


window = XCreateWindow(display, RootWindow(display, screen),
0, 0, 800, 600, 0, vi->depth, InputOutput,
vi->visual, CWColormap | CWBorderPixel | CWEventMask,
&swa);

// Set window properties


Atom props[2];
props[0] = XInternAtom(display, "_NET_WM_WINDOW_TYPE", False);
props[1] = XInternAtom(display, "_NET_WM_WINDOW_TYPE_DOCK", False);
XChangeProperty(display, window, props[0], XA_ATOM, 32,
PropModeReplace, (unsigned char*)&props[1], 1);

XMapWindow(display, window);
}

void initGL() {
// Initialize OpenGL context
glContext = glXCreateContext(display, nullptr, nullptr, GL_TRUE);
glXMakeCurrent(display, window, glContext);

// Initialize GLEW
if (glewInit() != GLEW_OK) {
throw std::runtime_error("Failed to initialize GLEW");
}

// Enable blending for transparency


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

void initShaders() {
// Compile and link shaders
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderSource, nullptr);
glCompileShader(vertexShader);

GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);


glShaderSource(fragmentShader, 1, &fragmentShaderSource, nullptr);
glCompileShader(fragmentShader);

shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);

glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
}

void initBuffers() {
// Create and bind vertex buffer
float vertices[] = {
// positions // texture coords
-1.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f,
1.0f, -1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 1.0f, 1.0f
};
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),


(void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
(void*)(2 * sizeof(float)));
glEnableVertexAttribArray(1);
}

void setupAnimations() {
// Initialize particle system for background effects
for (int i = 0; i < 100; i++) {
animation.particlePositions.push_back(static_cast<float>(rand()) /
RAND_MAX);
animation.particlePositions.push_back(static_cast<float>(rand()) /
RAND_MAX);
}
}

void handleEvent(const XEvent& event) {


if (event.type == KeyPress) {
char buffer[32];
KeySym keysym;
XLookupString(&event.xkey, buffer, sizeof(buffer), &keysym, nullptr);

if (keysym == XK_Return) {
validatePassword();
} else if (keysym == XK_BackSpace && !password.empty()) {
password.pop_back();
} else if (keysym == XK_Escape) {
cleanup();
exit(0);
} else if (strlen(buffer) == 1) {
password += buffer[0];
}
}
}

void update(float deltaTime) {


time += deltaTime;

// Update animation parameters


for (size_t i = 0; i < animation.particlePositions.size(); i += 2) {
animation.particlePositions[i] += deltaTime * 0.1f;
if (animation.particlePositions[i] > 1.0f) {
animation.particlePositions[i] = 0.0f;
}
}
}

void render() {
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(shaderProgram);
// Update uniforms
int width, height;
getWindowSize(&width, &height);
glUniform2f(glGetUniformLocation(shaderProgram, "resolution"),
static_cast<float>(width), static_cast<float>(height));
glUniform1f(glGetUniformLocation(shaderProgram, "time"), time);
glUniform3f(glGetUniformLocation(shaderProgram, "customColor"),
themeColor.r, themeColor.g, themeColor.b);

// Draw background
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

// Draw password dots


renderPasswordDots();

glXSwapBuffers(display, window);
}

void renderPasswordDots() {
// Render password visualization (dots)
for (size_t i = 0; i < password.length(); i++) {
// Draw animated dots for each character
float x = -0.5f + i * 0.1f;
float y = 0.0f;
float size = 0.02f + 0.005f * sin(time * 4.0f + i * 0.5f);

glPointSize(size * 100);
glBegin(GL_POINTS);
glColor4f(1.0f, 1.0f, 1.0f, 0.8f);
glVertex2f(x, y);
glEnd();
}
}

void validatePassword() {
// Add your password validation logic here
// This is a simple example - replace with secure validation
if (password == "your_secure_password") {
isAuthenticated = true;
cleanup();
exit(0);
}
password.clear();
}

void cleanup() {
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
glDeleteProgram(shaderProgram);
glXDestroyContext(display, glContext);
XDestroyWindow(display, window);
XCloseDisplay(display);
}

void getWindowSize(int* width, int* height) {


XWindowAttributes attributes;
XGetWindowAttributes(display, window, &attributes);
*width = attributes.width;
*height = attributes.height;
}
};

int main() {
try {
PasswordScreen passwordScreen;
passwordScreen.run();
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}

You might also like