IOT project -- Add a simple login function

in #utopian-io6 years ago (edited)

New Features

What feature(s) did you add?

  • Add web login web UI

    图片.png

  • Add login function and login validation

    GIF.gif


How did you implement it/them?

  • login.php

    <form action = "loginprocess.php" method="post">
    <input type="text" name= "username" class="text" value="" onfocus="this.value = '';" >
    <input type="password" name = "password" value="" onfocus="this.value = '';">
    <div class="submit"><input type="submit" onclick="myFunction()" value="Login"></div>
    

    Write a HTML to show the login form.,which user fill in the blank with their username and password

  • loginprocess.php

    <?php
    header("Content-type: text/html; charset=utf-8"); 
    include_once("conn.php");     
    session_start();  
    
    if(isset($_SESSION['login']))
    { 
    $username = $_POST['username'];
    $password = $_POST['password'];
    if(empty($username) || empty($password))
    {
    echo "<script>alert('please input username and password')</script>";
    echo '<script language=javascript>window.location.href="login.php"</script>'; 
    }
    
    $password = md5($password);
    
    $_SESSION['username'] = $username ;
    // $_SESSION['password'] = $password ;
    // echo "<a>..'$username'..</a>";
    $check_user = "SELECT * from user where username = '$username' and password = '$password'";
    $check_result = mysql_query($check_user);
    $check_exist = mysql_num_rows($check_result);
    // echo $check_result;
    if($check_exist)
    {
    
    echo "<script>alert('login succeed')</script>";
    echo '<script language=javascript>window.location.href="showInfoIndex.php"</script>'; 
    
    // exit();
    }
    else
    {
    echo "<script>alert('username or password error')</script>";
    echo '<script language=javascript>window.location.href="login.php"</script>'; 
    }
    
    }
    else
    {
    echo "<script>alert('error')</script>";
    echo '<script language=javascript>window.location.href="login.php"</script>'; 
    
    
    }
    
    
    ?>
    

    Through the HTTP POST request ,get the username and password which the user inputs.Then valid if the username and password are both right.

  • showInfoIndex.php

    <?php
    header("Content-type: text/html; charset=utf-8"); 
    include_once("conn.php"); 
    session_start();
    
    if(!isset($_SESSION['username']))
    {
    echo "<script>alert('please login first')</script>";
    echo '<script language=javascript>window.location.href="login.php"</script>'; 
    exit();
    }
    ?>
    

    When open the url of show sensor data in Web UI ,valid if username login or not firstly.


Roadmap

  • The function existing
    • Now , There are two ways to control the IOT smart hardware remotely.
    • Now,we can monitor several sensor data in the dynamic chart and Web UI.
    • Now ,we can actually show the sensors data in the dynamic chart in web UI.
    • Now, before we access the sensor data ,we need to login firstly.
  • In the future ,the IOT system will become more powerful
    • Perfect the login function.Consider more security factors.
    • Focusing more on UI design
    • Connect to the Home appliance with using relay module
    • Add more control and monitor way like discord controlling and so on.

How to contribute?

Github: https://github.com/Cha0s0000/IOT

  • Fork it!
  • Create your feature branch: git checkout -b my-new-feature
  • Commit your changes: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request.



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Your contribution cannot be approved because it does not follow the Utopian Rules.

Outdated or low quality code can lead to rejection.

We had to change the decision because your code contains deprecated and vulnerable code.

http://php.net/manual/en/function.mysql-query.php

http://php.net/manual/en/security.database.sql-injection.php

You can contact us on Discord.
[utopian-moderator]

Yeah . That is .I just use it in the local computer. So I do not consider the secure factors like sql injection and so on

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Coin Marketplace

STEEM 0.31
TRX 0.11
JST 0.030
BTC 67598.23
ETH 3714.51
USDT 1.00
SBD 3.71