Monday 20 March 2017

How to write in bold using ncurses in C

To use ncurses in your program, you first need to install ncurses. Once installed, write the below code:

#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
  int ch;
  initscr();
  raw();
  keypad(stdscr, TRUE);
  noecho();
  printw("Type any character to see it in bold\n");
  ch = getch();
  if (ch == KEY_F(1))
    printw("F1 Key pressed");
  else {
    printw("The pressed key is ");
    attron(A_BOLD);
    printw("%c", ch);
    attroff(A_BOLD);
  }
  refresh();
  getch();
  endwin();
  return EXIT_SUCCESS;
}

To compile it, use the ncurses library using
$ gcc file.c -lncurses

Once compiled, it will generate a executable named a.out

Type any character to see it in bold
The pressed key is A

If you need any help installing ncurses, write in comment section.

Thursday 16 March 2017

Generating password using openssl for your unix accounts

There is a need when you need to create an account using password hash, follow below steps to simply create password hash.

$ openssl passwd -1
Password: <your pass>
Verifying - Password: <your pass>
Hash will appear here as an output

openssl is the command to generate password
passwd is an argument and -1 represents here that we want unix kind of hash from passwords as an output. There are other options too, like md5, crypt.

For example, you can use:

$ openssl passwd -crypt
or,
$ openssl passwd -md5

You can also provide the salt, to enhance the security

$ openssl passwd -crypt -salt (yourSalt)

This salt is required to decrypt the password.

You can also use python crypt function to create encrypted hashes:


# PASS="strongpass" python -c "import crypt; import os; print crypt.crypt(os.environ['PASS'], 'salt')"&
# ps fauxwww | grep 'python -c'

In this manner, the password will not appear in ps output.

To hide from history, you can disable and enable the history using following option
set +o history
# PASS="strongpass" python -c "import crypt; import os; print crypt.crypt(os.environ['PASS'], 'salt')"&
set -o history

So, go ahead and generate your hashes.

RAINBOW ROSE in shell script

To gift your friend, you can send him/her a rainbow rose by using below shell script

#!/bin/bash
RED='\033[1;31m'
GREEN='\033[1;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'

printf "${RED}    .--.---.\n"
sleep 1;
printf "   ( ${CYAN}\'--'/${RED} )\n"
sleep 1;
printf "  ( ${CYAN}'..-...'${RED} )\n"
sleep 1;
printf "   '.${CYAN}'-._.'${RED}.'\n"
sleep 1;
printf "    <'${CYAN}-.,.${RED}->\n"
sleep 1;
printf "${GREEN}       \`\\(  ${YELLOW}  _\n"
sleep 1;
printf "${GREEN}        < \ ${YELLOW} / \ \n"
sleep 1;
printf "       ${YELLOW}__${GREEN} \\\\\\ $YELLOW|_/\n"
sleep 1;
printf "      /  \ ${GREEN}\\\\\\ \n"
sleep 1;
printf "      ${YELLOW}'--'.${GREEN}\\\\\\ ${YELLOW}>\n"
sleep 1;
printf "${GREEN}            \\\\\\   \n"
printf "\n"
printf "${CYAN}RAI${RED}NBOW${GREEN} ${RED}ROSE${RED} FOR ${CYAN}YOU${CYAN} ${GREEN}MY${YELLOW} FRIEND\n"

And it will look like this: